From 3f2be132bdf058c3ced3afe6a0881870afc3e064 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 21 Jan 2015 22:40:31 -0500 Subject: [PATCH 1/3] VRFS-2539 protect against error during notification load if the related session is missing / clean up the notifications of nonexistent sessions --- ruby/lib/jam_ruby/models/music_session.rb | 1 + ruby/lib/jam_ruby/models/notification.rb | 9 ++++++-- .../assets/javascripts/notificationPanel.js | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index f59e0ca21..a29d0b2f9 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -427,6 +427,7 @@ module JamRuby # returns one user history per user, with instruments all crammed together, and with total duration def unique_user_histories + # only get the active users if the session is in progress user_filter = "music_sessions_user_history.session_removed_at is null" if self.session_removed_at.nil? MusicSessionUserHistory diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index 5fa628f3a..e0ec6590b 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -42,7 +42,7 @@ module JamRuby # used for persisted notifications def formatted_msg # target_user, band, session, recording, invitation, join_request = nil - source_user, band = nil + source_user, band, session = nil unless self.source_user_id.nil? source_user = User.find(self.source_user_id) @@ -53,7 +53,12 @@ module JamRuby end unless self.session_id.nil? - session = MusicSession.find(self.session_id) + session = MusicSession.find_by_id(self.session_id) + + # remove all notifications related to this session if it's not found + if session.nil? + Notification.delete_all "(session_id = '#{session_id}')" + end end self.class.format_msg(self.description, {:user => source_user, :band => band, :session => session}) diff --git a/web/app/assets/javascripts/notificationPanel.js b/web/app/assets/javascripts/notificationPanel.js index ca393b18d..fdf0ac3ee 100644 --- a/web/app/assets/javascripts/notificationPanel.js +++ b/web/app/assets/javascripts/notificationPanel.js @@ -207,19 +207,24 @@ isLoading = true; // retrieve pending notifications for this user rest.getNotifications(buildParams()) - .done(function(response) { - updateNotificationList(response); - isLoading = false; - }) - .fail(function() { - isLoading = false; - app.ajaxError(); - }) + .done(function(response) { + updateNotificationList(response); + isLoading = false; + }) + .fail(function() { + isLoading = false; + app.ajaxError(); + }) } function updateNotificationList(response) { $.each(response, function(index, val) { + // this means the session no longer exists + if (response.fan_access == null && response.musician_access == null) { + return; + } + if(val.description == context.JK.MessageType.TEXT_MESSAGE) { val.formatted_msg = textMessageDialog.formatTextMessage(val.message.substring(0, 200), val.source_user_id, val.source_user.name, val.message.length > 200).html(); } From 65f1f0fe79cdabfdb090ede191ce33612ded09bb Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 23 Jan 2015 14:50:09 -0600 Subject: [PATCH 2/3] * VRFS-2640 - double-check if jobs are concurrent safe --- ruby/lib/jam_ruby/resque/scheduled/cleanup_facebook_signup.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/lib/jam_ruby/resque/scheduled/cleanup_facebook_signup.rb b/ruby/lib/jam_ruby/resque/scheduled/cleanup_facebook_signup.rb index c8f67120b..ddfb6b28f 100644 --- a/ruby/lib/jam_ruby/resque/scheduled/cleanup_facebook_signup.rb +++ b/ruby/lib/jam_ruby/resque/scheduled/cleanup_facebook_signup.rb @@ -1,12 +1,12 @@ module JamRuby class CleanupFacebookSignup + extend Resque::Plugins::JamLonelyJob @queue = :scheduled_cleanup_facebook_signup @@log = Logging.logger[CleanupFacebookSignup] - def self.perform @@log.debug("waking up") From 8556aaac139ff17fc1fca724d3cb16a8940c7157 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 23 Jan 2015 16:51:59 -0600 Subject: [PATCH 3/3] * make dynamic registrations confgurable, in case server crashes again: VRFS-2645 --- web/app/assets/javascripts/jquery.listenbroadcast.js | 6 ++++-- websocket-gateway/bin/websocket_gateway | 1 + websocket-gateway/config/application.yml | 1 + websocket-gateway/lib/jam_websockets/router.rb | 11 +++++++---- websocket-gateway/lib/jam_websockets/server.rb | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/web/app/assets/javascripts/jquery.listenbroadcast.js b/web/app/assets/javascripts/jquery.listenbroadcast.js index 95c806af2..73837da8f 100644 --- a/web/app/assets/javascripts/jquery.listenbroadcast.js +++ b/web/app/assets/javascripts/jquery.listenbroadcast.js @@ -535,8 +535,10 @@ var $box = $(box) $mountState = $box.find('.listen-broadcast-state') - updateMountInfo(mountInfo) - updateMountDetails(mountInfo); + if(mountInfo) { + updateMountInfo(mountInfo) + updateMountDetails(mountInfo); + } } function updateMountInfo(mount) { diff --git a/websocket-gateway/bin/websocket_gateway b/websocket-gateway/bin/websocket_gateway index c3e09141d..456592701 100755 --- a/websocket-gateway/bin/websocket_gateway +++ b/websocket-gateway/bin/websocket_gateway @@ -72,5 +72,6 @@ Server.new.run(:port => config["port"] + (jam_instance-1 ) * 2, :influxdb_password => config['influxdb_password'], :influxdb_hosts => config['influxdb_hosts'], :influxdb_port => config['influxdb_port'], + :allow_dynamic_registration => config['allow_dynamic_registration'], :cidr => config['cidr'], :gateway_name => gateway_name) diff --git a/websocket-gateway/config/application.yml b/websocket-gateway/config/application.yml index 58b8bffd7..c01f4e5af 100644 --- a/websocket-gateway/config/application.yml +++ b/websocket-gateway/config/application.yml @@ -10,6 +10,7 @@ Defaults: &defaults influxdb_password: "root" influxdb_hosts: ["localhost"] influxdb_port: 8086 + allow_dynamic_registration: true development: port: 6767 diff --git a/websocket-gateway/lib/jam_websockets/router.rb b/websocket-gateway/lib/jam_websockets/router.rb index cf00b389b..fe2cb1bda 100644 --- a/websocket-gateway/lib/jam_websockets/router.rb +++ b/websocket-gateway/lib/jam_websockets/router.rb @@ -61,7 +61,7 @@ module JamWebsockets @disconnected_count = 0 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'}, &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}, &block) @log.info "startup" @@ -73,6 +73,7 @@ module JamWebsockets @connect_time_expire_browser = connect_time_expire_browser @max_connections_per_user = options[:max_connections_per_user] @gateway_name = options[:gateway] + @allow_dynamic_registration = options[:allow_dynamic_registration] begin @amqp_connection_manager = AmqpConnectionManager.new(true, 4, :host => options[:host], :port => options[:port]) @@ -327,7 +328,9 @@ module JamWebsockets if clients.length == 0 # if there are no more clients listening, then unsubscribe to the topic for this mount_id - @subscription_topic.unbind(@subscriptions_exchange, :routing_key => "subscription.#{type}.#{id}") + routing_key = "subscription.#{type}.#{id}" + @log.debug("unregister dynamic topic #{routing_key}") + @subscription_topic.unbind(@subscriptions_exchange, :routing_key => routing_key) end end @@ -804,7 +807,7 @@ module JamWebsockets id = subscribe.id type = subscribe.type if id && id.length > 0 && type && type.length > 0 - #register_subscription(client, type, id) + register_subscription(client, type, id) if @allow_dynamic_registration else @log.error("handle_subscribe: empty data #{subscribe}") end @@ -814,7 +817,7 @@ module JamWebsockets id = unsubscribe.id type = unsubscribe.type if id && id.length > 0 && type && type.length > 0 - #unregister_subscription(client, type, id) + unregister_subscription(client, type, id) if @allow_dynamic_registration else @log.error("handle_subscribe: empty data #{unsubscribe}") end diff --git a/websocket-gateway/lib/jam_websockets/server.rb b/websocket-gateway/lib/jam_websockets/server.rb index d55d6fce5..fd45f7c42 100644 --- a/websocket-gateway/lib/jam_websockets/server.rb +++ b/websocket-gateway/lib/jam_websockets/server.rb @@ -24,6 +24,7 @@ module JamWebsockets gateway_name = options[:gateway_name] rabbitmq_host = options[:rabbitmq_host] rabbitmq_port = options[:rabbitmq_port].to_i + allow_dynamic_registration = options[:allow_dynamic_registration].nil? ? true : options[:allow_dynamic_registration] Stats::init(options) @@ -39,7 +40,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) 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) do start_connection_expiration start_client_expiration start_connection_flagger