From 52287d054fcb744ea239963e36296301a905c818 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 23 Jul 2013 22:01:51 -0500 Subject: [PATCH] * VRFS-430; found another edge case on initialization of websocket-gateway requiring rework of startup code --- lib/jam_websockets/router.rb | 3 ++- lib/jam_websockets/server.rb | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/jam_websockets/router.rb b/lib/jam_websockets/router.rb index 94fd6e581..f602f577d 100644 --- a/lib/jam_websockets/router.rb +++ b/lib/jam_websockets/router.rb @@ -38,7 +38,7 @@ module JamWebsockets end - def start(connect_time_stale, options={:host => "localhost", :port => 5672}) + def start(connect_time_stale, options={:host => "localhost", :port => 5672}, &block) @log.info "startup" @@ -48,6 +48,7 @@ module JamWebsockets @amqp_connection_manager = AmqpConnectionManager.new(true, 4, :host => options[:host], :port => options[:port]) @amqp_connection_manager.connect do |channel| register_topics(channel) + block.call end rescue => e diff --git a/lib/jam_websockets/server.rb b/lib/jam_websockets/server.rb index 3000c36af..7607175c2 100644 --- a/lib/jam_websockets/server.rb +++ b/lib/jam_websockets/server.rb @@ -20,21 +20,22 @@ module JamWebsockets @log.info "starting server #{host}:#{port} with staleness_time=#{connect_time_stale}; reconnect time = #{connect_time_expire}" EventMachine.run do - @router.start(connect_time_stale) + @router.start(connect_time_stale) do + # take stale off the expire limit because the call to stale will + # touch the updated_at column, adding an extra stale limit to the expire time limit + expire_time = connect_time_expire > connect_time_stale ? connect_time_expire - connect_time_stale : connect_time_expire + start_connection_expiration(expire_time) + start_connection_flagger(connect_time_stale) + + start_websocket_listener(host, port, options[:emwebsocket_debug]) + end # if you don't do this, the app won't exit unless you kill -9 at_exit do @log.info "cleaning up server" @router.cleanup end - - # take stale off the expire limit because the call to stale will - # touch the updated_at column, adding an extra stale limit to the expire time limit - expire_time = connect_time_expire > connect_time_stale ? connect_time_expire - connect_time_stale : connect_time_expire - start_connection_expiration(expire_time) - start_connection_flagger(connect_time_stale) - start_websocket_listener(host, port, options[:emwebsocket_debug]) end end