diff --git a/config/initializers/message_bus.rb b/config/initializers/message_bus.rb index a61d379e374..ad12cf1c7db 100644 --- a/config/initializers/message_bus.rb +++ b/config/initializers/message_bus.rb @@ -31,3 +31,4 @@ MessageBus.is_admin_lookup do |env| end MessageBus.cache_assets = !Rails.env.development? +MessageBus.enable_diagnostics diff --git a/vendor/gems/message_bus/assets/application.js b/vendor/gems/message_bus/assets/application.js index 6f8f8302297..6347f926cef 100644 --- a/vendor/gems/message_bus/assets/application.js +++ b/vendor/gems/message_bus/assets/application.js @@ -1,5 +1,4 @@ - window.App = Ember.Application.createWithMixins({ start: function(){ MessageBus.start(); @@ -29,7 +28,7 @@ App.IndexModel = Ember.Object.extend({ this.set("discovering", true); Ember.run.later(function(){ _this.set("discovering", false); - }, 20 * 1000); + }, 1 * 1000); $.post("/message-bus/_diagnostics/discover"); diff --git a/vendor/gems/message_bus/assets/message-bus.js b/vendor/gems/message_bus/assets/message-bus.js index 0b0be03805a..bec7c2344ef 100644 --- a/vendor/gems/message_bus/assets/message-bus.js +++ b/vendor/gems/message_bus/assets/message-bus.js @@ -30,6 +30,24 @@ window.MessageBus = (function() { } }; + var processMessages = function(messages) { + failCount = 0; + $.each(messages,function(idx,message) { + gotData = true; + $.each(callbacks,function(idx,callback) { + if (callback.channel === message.channel) { + callback.last_id = message.message_id; + callback.func(message.data); + } + if (message["channel"] === "/__status") { + if (message.data[callback.channel] !== void 0) { + callback.last_id = message.data[callback.channel]; + } + } + }); + }); + }; + return { enableLongPolling: true, @@ -52,7 +70,7 @@ window.MessageBus = (function() { return; } data = {}; - callbacks.each(function(c) { + $.each(callbacks, function(idx,c) { return data[c.channel] = c.last_id === void 0 ? -1 : c.last_id; }); gotData = false; @@ -65,21 +83,7 @@ window.MessageBus = (function() { 'X-SILENCE-LOGGER': 'true' }, success: function(messages) { - failCount = 0; - return messages.each(function(message) { - gotData = true; - return callbacks.each(function(callback) { - if (callback.channel === message.channel) { - callback.last_id = message.message_id; - callback.func(message.data); - } - if (message["channel"] === "/__status") { - if (message.data[callback.channel] !== void 0) { - callback.last_id = message.data[callback.channel]; - } - } - }); - }); + processMessages(messages); }, error: failCount += 1, complete: function() { diff --git a/vendor/gems/message_bus/lib/message_bus.rb b/vendor/gems/message_bus/lib/message_bus.rb index 72d859cd125..1948e74c778 100644 --- a/vendor/gems/message_bus/lib/message_bus.rb +++ b/vendor/gems/message_bus/lib/message_bus.rb @@ -125,6 +125,12 @@ module MessageBus::Implementation @reliable_pub_sub ||= MessageBus::ReliablePubSub.new redis_config end + def enable_diagnostics + subscribe('/discover') do |msg| + MessageBus.publish '/process-discovery', Process.pid, user_id: msg.data[:user_id] + end + end + def publish(channel, data, opts = nil) return if @off diff --git a/vendor/gems/message_bus/lib/message_bus/rack/diagnostics.rb b/vendor/gems/message_bus/lib/message_bus/rack/diagnostics.rb index 6b1e4e59dd2..a286a4d5ebc 100644 --- a/vendor/gems/message_bus/lib/message_bus/rack/diagnostics.rb +++ b/vendor/gems/message_bus/lib/message_bus/rack/diagnostics.rb @@ -71,8 +71,9 @@ HTML return index unless route - if route == 'discover' - MessageBus.publish('/discover', {user_id: MessageBus() }) + if route == '/discover' + MessageBus.publish('/discover', {user_id: MessageBus.user_id_lookup.call(env)}) + return [200, {}, ['ok']] end asset = route.split('/assets/')[1]