From 2e81bafb01a46a319fd4064bf884a1197e515bb4 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 8 Feb 2016 06:56:54 -0600 Subject: [PATCH] * try out chat blast with no inactivity. fix 5 instrument validation pain --- ruby/lib/jam_ruby/base_manager.rb | 18 ++++++++++--- ruby/lib/jam_ruby/models/user.rb | 8 +++--- .../stores/ChatStore.js.coffee | 26 ++++++++++--------- web/app/helpers/client_helper.rb | 1 + web/config/application.rb | 1 + websocket-gateway/bin/websocket_gateway | 6 +++-- websocket-gateway/config/application.yml | 2 ++ .../lib/jam_websockets/router.rb | 8 +++--- .../lib/jam_websockets/server.rb | 3 ++- 9 files changed, 47 insertions(+), 26 deletions(-) diff --git a/ruby/lib/jam_ruby/base_manager.rb b/ruby/lib/jam_ruby/base_manager.rb index 49dcff5d5..401f7c3bb 100644 --- a/ruby/lib/jam_ruby/base_manager.rb +++ b/ruby/lib/jam_ruby/base_manager.rb @@ -2,11 +2,14 @@ module JamRuby class BaseManager attr_accessor :pg_conn - + + @@in_websocket_gateway = Rails.env != 'test' && Object.const_defined?("JamRuby::UserManager") == false + def initialize(options={}) @log = Logging.logger[self] @pg_conn = options[:conn] + unless PG.threadsafe? raise Exception, "a non-threadsafe build of libpq is present." end @@ -22,12 +25,19 @@ module JamRuby # across Rails ActiveRecord and the pg-gem based code in ConnectionManager. manager.pg_conn = connection.instance_variable_get("@connection") - begin + if @@in_websocket_gateway + # it only necessary to catch exceptions in websocket-gateway, which has only one AR connection and does not clean it up like a Rails context does + begin + connection.transaction do + yield manager + end + rescue Exception => e + ActiveRecord::Base.connection.execute('ROLLBACK') + end + else connection.transaction do yield manager end - rescue Exception => e - ActiveRecord::Base.connection.execute('ROLLBACK') end end end diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index a2c2330f4..45437306d 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -41,7 +41,7 @@ module JamRuby attr_accessible :first_name, :last_name, :email, :city, :password, :password_confirmation, :state, :country, :birth_date, :subscribe_email, :terms_of_service, :original_fpfile, :cropped_fpfile, :cropped_large_fpfile, :cropped_s3_path, :cropped_large_s3_path, :photo_url, :large_photo_url, :crop_selection # updating_password corresponds to a lost_password - attr_accessor :updating_password, :updating_email, :updated_email, :update_email_confirmation_url, :administratively_created, :current_password, :setting_password, :confirm_current_password, :updating_avatar, :updating_progression_field, :mods_json, :expecting_gift_card + attr_accessor :validate_instruments, :updating_password, :updating_email, :updated_email, :update_email_confirmation_url, :administratively_created, :current_password, :setting_password, :confirm_current_password, :updating_avatar, :updating_progression_field, :mods_json, :expecting_gift_card belongs_to :icecast_server_group, class_name: "JamRuby::IcecastServerGroup", inverse_of: :users, foreign_key: 'icecast_server_group_id' @@ -226,7 +226,7 @@ module JamRuby validates_numericality_of :paid_sessions_daily_rate, greater_than: 0, less_than: 5000000, :if => :paid_sessions # custom validators - validate :validate_musician_instruments + validate :validate_musician_instruments, if: :validate_instruments validate :validate_current_password validate :validate_update_email validate :validate_avatar_info @@ -1068,7 +1068,7 @@ module JamRuby gift_card = options[:gift_card] user = User.new - + user.validate_instruments = true UserManager.active_record_transaction do |user_manager| user.first_name = first_name user.last_name = last_name @@ -1441,7 +1441,7 @@ module JamRuby # there are plenty of confirmed users with nil signup_tokens, so we can't look on it raise ActiveRecord::RecordNotFound else - UserManager.active_record_transaction do |user_manager| + User.transaction do # throws ActiveRecord::RecordNotFound if invalid user = User.find_by_signup_token!(signup_token) user.signup_confirm diff --git a/web/app/assets/javascripts/react-components/stores/ChatStore.js.coffee b/web/app/assets/javascripts/react-components/stores/ChatStore.js.coffee index 60b90e5af..f687b1eb0 100644 --- a/web/app/assets/javascripts/react-components/stores/ChatStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/ChatStore.js.coffee @@ -24,19 +24,21 @@ SessionStore = context.SessionStore @fetchHistory() onUserActivityChanged: (state) -> - systemMsg = {} - @systemMsgId = @systemMsgId + 1 - systemMsg.sender_name = 'System' - systemMsg.sender_id = 'system' - systemMsg.msg_id = @systemMsgId - systemMsg.created_at = new Date().toISOString() - systemMsg.channel = 'global' - if state.active - systemMsg.msg = "You've come back!" - else - systemMsg.msg = "You've become inactive. Any global chat messages while away will be missed." - @onMsgReceived(systemMsg) + if !gon.chat_blast + systemMsg = {} + @systemMsgId = @systemMsgId + 1 + systemMsg.sender_name = 'System' + systemMsg.sender_id = 'system' + systemMsg.msg_id = @systemMsgId + systemMsg.created_at = new Date().toISOString() + systemMsg.channel = 'global' + if state.active + systemMsg.msg = "You've come back!" + else + systemMsg.msg = "You've become inactive. Any global chat messages while away will be missed." + + @onMsgReceived(systemMsg) # after the animation to open the chat panel is done, do it! onFullyOpened: () -> diff --git a/web/app/helpers/client_helper.rb b/web/app/helpers/client_helper.rb index aa4758613..151d2394d 100644 --- a/web/app/helpers/client_helper.rb +++ b/web/app/helpers/client_helper.rb @@ -71,6 +71,7 @@ module ClientHelper gon.band_search_meta = BandSearch.search_filter_meta gon.session_stat_thresholds = Rails.application.config.session_stat_thresholds gon.midi_enabled = Rails.application.config.midi_enabled + gon.chat_blast = Rails.application.config.chat_blast # is this the native client or browser? @nativeClient = is_native_client? diff --git a/web/config/application.rb b/web/config/application.rb index 5275a0a52..2b8df7a47 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -417,5 +417,6 @@ if defined?(Bundler) config.check_bounced_emails = false config.ban_jamtrack_downloaders = true config.chat_opened_by_default = true + config.chat_blast = true end end diff --git a/websocket-gateway/bin/websocket_gateway b/websocket-gateway/bin/websocket_gateway index 0045cd96a..fe366e425 100755 --- a/websocket-gateway/bin/websocket_gateway +++ b/websocket-gateway/bin/websocket_gateway @@ -60,7 +60,7 @@ Object.send(:remove_const, :Rails) # this is to 'fool' new relic into not thinki gateway_name = ENV['GATEWAY_NAME'] || 'default' gateway_name = "#{gateway_name}-#{jam_instance}" -Server.new.run(:port => config["port"] + (jam_instance-1 ) * 2, +Server.new.run(:port => config["port"] + (jam_instance - 1 ) * 2, :emwebsocket_debug => config["emwebsocket_debug"], :connect_time_stale_client => config["connect_time_stale_client"], :connect_time_expire_client => config["connect_time_expire_client"], @@ -76,4 +76,6 @@ Server.new.run(:port => config["port"] + (jam_instance-1 ) * 2, :influxdb_port => config['influxdb_port'], :allow_dynamic_registration => config['allow_dynamic_registration'], :cidr => config['cidr'], - :gateway_name => gateway_name) + :gateway_name => gateway_name, + :chat_enabled => config['chat_enabled'], + :chat_blast => config['chat_blast']) diff --git a/websocket-gateway/config/application.yml b/websocket-gateway/config/application.yml index c01f4e5af..6c936b7d7 100644 --- a/websocket-gateway/config/application.yml +++ b/websocket-gateway/config/application.yml @@ -11,6 +11,8 @@ Defaults: &defaults influxdb_hosts: ["localhost"] influxdb_port: 8086 allow_dynamic_registration: true + chat_enabled: true + chat_blast: true development: port: 6767 diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index 9feed29af..62f5b6b87 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -68,7 +68,8 @@ module JamWebsockets @profile_it_sums = {} @heartbeat_tracker = {} @temp_ban = {} - @chat_enabled = {} + @chat_enabled = true + @chat_blast = true @login_success_count = 0 @login_fail_count = 0 @@ -81,7 +82,7 @@ module JamWebsockets end - def start(connect_time_stale_client, connect_time_expire_client, connect_time_stale_browser, connect_time_expire_browser, options={:host => "localhost", :port => 5672, :max_connections_per_user => 10, :gateway => 'default', :allow_dynamic_registration => true, chat_enabled => true}, &block) + def start(connect_time_stale_client, connect_time_expire_client, connect_time_stale_browser, connect_time_expire_browser, options={:host => "localhost", :port => 5672, :max_connections_per_user => 10, :gateway => 'default', :allow_dynamic_registration => true, :chat_enabled => true, :chat_blast => true}, &block) @log.info "startup" @@ -95,6 +96,7 @@ module JamWebsockets @gateway_name = options[:gateway] @allow_dynamic_registration = options[:allow_dynamic_registration] @chat_enabled = options[:chat_enabled] + @chat_blast = options[:chat_blast] # determine the maximum amount of heartbeats we should get per user @maximum_minutely_heartbeat_rate_client = ((@heartbeat_interval_client / 60.0) * 2).ceil + 3 @@ -244,7 +246,7 @@ module JamWebsockets msg = Jampb::ClientMessage.parse(msg) @log.debug "client-directed message received from #{msg.from} to all chat clients" @client_lookup.each do |client_id, client_context| - if client_context.active + if @chat_blast || client_context.active client = client_context.client if client diff --git a/websocket-gateway/lib/jam_websockets/server.rb b/websocket-gateway/lib/jam_websockets/server.rb index 2521a0b14..22ecba57b 100644 --- a/websocket-gateway/lib/jam_websockets/server.rb +++ b/websocket-gateway/lib/jam_websockets/server.rb @@ -24,6 +24,7 @@ module JamWebsockets connect_time_expire_browser = options[:connect_time_expire_browser].to_i max_connections_per_user = options[:max_connections_per_user].to_i chat_enabled = options[:chat_enabled].nil? ? true : options[:chat_enabled] + chat_blast = options[:chat_blast].nil? ? true : options[:chat_blast] gateway_name = options[:gateway_name] rabbitmq_host = options[:rabbitmq_host] rabbitmq_port = options[:rabbitmq_port].to_i @@ -44,7 +45,7 @@ module JamWebsockets } EventMachine.run do - @router.start(connect_time_stale_client, connect_time_expire_client, connect_time_stale_browser, connect_time_expire_browser, host: rabbitmq_host, port: rabbitmq_port, max_connections_per_user: max_connections_per_user, gateway: gateway_name, allow_dynamic_registration: allow_dynamic_registration, chat_enabled: chat_enabled) do + @router.start(connect_time_stale_client, connect_time_expire_client, connect_time_stale_browser, connect_time_expire_browser, host: rabbitmq_host, port: rabbitmq_port, max_connections_per_user: max_connections_per_user, gateway: gateway_name, allow_dynamic_registration: allow_dynamic_registration, chat_enabled: chat_enabled, chat_blast: chat_blast) do start_connection_expiration start_client_expiration start_connection_flagger