renamed connection timers to correspond to state names

This commit is contained in:
Jonathan Kolyer 2013-02-11 00:04:41 -06:00
parent 2140eff3bd
commit 1c1949010e
4 changed files with 26 additions and 20 deletions

View File

@ -33,5 +33,5 @@ end
ActiveRecord::Base.establish_connection(db_config)
Server.new.run(:port => config["port"],
:emwebsocket_debug => config["emwebsocket_debug"],
:max_stale_connection_time => config["max_stale_connection_time"],
:max_reconnect_time => config["max_reconnect_time"])
:connect_time_stale => config["connect_time_stale"],
:connect_time_expire => config["connect_time_expire"])

View File

@ -1,6 +1,6 @@
Defaults: &defaults
max_stale_connection_time: 30
max_reconnect_time: 180
connect_time_stale: 30
connect_time_expire: 180
development:
port: 6767

View File

@ -39,11 +39,11 @@ module JamWebsockets
end
def start(max_stale_connection_time, options={:host => "localhost", :port => 5672})
def start(connect_time_stale, options={:host => "localhost", :port => 5672})
@log.info "startup"
@heartbeat_interval = max_stale_connection_time / 2
@heartbeat_interval = connect_time_stale / 2
begin
@connection = AMQP.connect(:host => options[:host], :port => options[:port])

View File

@ -14,13 +14,13 @@ module JamWebsockets
host = "0.0.0.0"
port = options[:port]
max_stale_connection_time = options[:max_stale_connection_time]
max_reconnect_time = options[:max_reconnect_time]
connect_time_stale = options[:connect_time_stale].to_i
connect_time_expire = options[:connect_time_expire].to_i
@log.info "starting server #{host}:#{port} with staleness_time=#{max_stale_connection_time}"
@log.info "starting server #{host}:#{port} with staleness_time=#{connect_time_stale}; reconnect time = #{connect_time_expire}"
EventMachine.run do
@router.start(max_stale_connection_time)
@router.start(connect_time_stale)
# if you don't do this, the app won't exit unless you kill -9
at_exit do
@ -28,8 +28,8 @@ module JamWebsockets
@router.cleanup
end
start_connection_flagger(max_stale_connection_time)
start_connection_cleaner(max_reconnect_time)
start_connection_expiration(connect_time_expire)
start_connection_flagger(connect_time_stale)
start_websocket_listener(host, port, options[:emwebsocket_debug])
end
@ -42,34 +42,40 @@ module JamWebsockets
end
end
def start_connection_cleaner(stale_max_time)
def start_connection_expiration(stale_max_time)
# one cleanup on startup
cleanup_stale_connections(stale_max_time)
@log.info("*** start_connection_expiration: #{stale_max_time}")
EventMachine::PeriodicTimer.new(15) do
cleanup_stale_connections(stale_max_time)
expire_stale_connections(stale_max_time)
EventMachine::PeriodicTimer.new(stale_max_time) do
@log.info("*** start_connection_expiration: TIMER #{stale_max_time}")
expire_stale_connections(stale_max_time)
end
end
def cleanup_stale_connections(stale_max_time)
def expire_stale_connections(stale_max_time)
ConnectionManager.active_record_transaction do |connection_manager|
connection_manager.remove_stale_connections(stale_max_time)
connection_manager.expire_stale_connections(stale_max_time)
end
end
def start_connection_flagger(flag_max_time)
@log.info("*** start_connection_flagger: #{flag_max_time}")
# one cleanup on startup
flag_stale_connections(flag_max_time)
EventMachine::PeriodicTimer.new(15) do
EventMachine::PeriodicTimer.new(flag_max_time) do
@log.info("*** start_connection_flagger: TIMER #{flag_max_time}")
flag_stale_connections(flag_max_time)
end
end
def flag_stale_connections(flag_max_time)
ConnectionManager.active_record_transaction do |connection_manager|
@log.info("*** flag_stale_connections: TIMER #{flag_max_time}")
connection_manager.flag_stale_connections(flag_max_time)
end
end