vrfs192: added aasm gem; added max_reconnect_time parameter
This commit is contained in:
parent
12822972ab
commit
2140eff3bd
1
Gemfile
1
Gemfile
|
|
@ -28,6 +28,7 @@ gem 'will_paginate'
|
|||
gem 'actionmailer'
|
||||
gem 'sendgrid'
|
||||
gem 'rb-readline'
|
||||
gem 'aasm', '3.0.16'
|
||||
|
||||
group :development do
|
||||
gem 'pry'
|
||||
|
|
|
|||
|
|
@ -31,4 +31,7 @@ else
|
|||
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"]
|
||||
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"])
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
Defaults: &defaults
|
||||
max_stale_connection_time: 30
|
||||
max_reconnect_time: 180
|
||||
|
||||
development:
|
||||
port: 6767
|
||||
verbose: true
|
||||
emwebsocket_debug: false
|
||||
max_stale_connection_time: 30
|
||||
<<: *defaults
|
||||
|
||||
test:
|
||||
port: 6769
|
||||
verbose: true
|
||||
max_stale_connection_time: 30
|
||||
<<: *defaults
|
||||
|
||||
production:
|
||||
port: 6767
|
||||
verbose: false
|
||||
max_stale_connection_time: 30
|
||||
<<: *defaults
|
||||
|
|
|
|||
|
|
@ -433,9 +433,15 @@ module JamWebsockets
|
|||
|
||||
# respond with LOGIN_ACK to let client know it was successful
|
||||
#binding.pry
|
||||
|
||||
connection = JamRuby::Connection.find_by_client_id(client_id)
|
||||
|
||||
remote_ip = extract_ip(client)
|
||||
login_ack = @message_factory.login_ack(remote_ip, client_id, user.remember_token, @heartbeat_interval)
|
||||
login_ack = @message_factory.login_ack(remote_ip,
|
||||
client_id,
|
||||
user.remember_token,
|
||||
@heartbeat_interval,
|
||||
connection.try(:music_session_id))
|
||||
send_to_client(client, login_ack)
|
||||
|
||||
@semaphore.synchronize do
|
||||
|
|
@ -448,9 +454,13 @@ module JamWebsockets
|
|||
add_user(context)
|
||||
add_client(client_id, client) # TODO
|
||||
|
||||
# log this connection in the database
|
||||
ConnectionManager.active_record_transaction do |connection_manager|
|
||||
connection_manager.create_connection(user.id, client.client_id, extract_ip(client))
|
||||
if connection
|
||||
connection.connect!
|
||||
else
|
||||
# log this connection in the database
|
||||
ConnectionManager.active_record_transaction do |connection_manager|
|
||||
connection_manager.create_connection(user.id, client.client_id, extract_ip(client))
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ 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]
|
||||
|
||||
@log.info "starting server #{host}:#{port} with staleness_time=#{max_stale_connection_time}"
|
||||
|
||||
|
|
@ -27,7 +28,8 @@ module JamWebsockets
|
|||
@router.cleanup
|
||||
end
|
||||
|
||||
start_connection_cleaner(max_stale_connection_time)
|
||||
start_connection_flagger(max_stale_connection_time)
|
||||
start_connection_cleaner(max_reconnect_time)
|
||||
|
||||
start_websocket_listener(host, port, options[:emwebsocket_debug])
|
||||
end
|
||||
|
|
@ -56,6 +58,22 @@ module JamWebsockets
|
|||
connection_manager.remove_stale_connections(stale_max_time)
|
||||
end
|
||||
end
|
||||
|
||||
def start_connection_flagger(flag_max_time)
|
||||
# one cleanup on startup
|
||||
flag_stale_connections(flag_max_time)
|
||||
|
||||
EventMachine::PeriodicTimer.new(15) do
|
||||
flag_stale_connections(flag_max_time)
|
||||
end
|
||||
end
|
||||
|
||||
def flag_stale_connections(flag_max_time)
|
||||
ConnectionManager.active_record_transaction do |connection_manager|
|
||||
connection_manager.flag_stale_connections(flag_max_time)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ def login(router, user, password, client_id)
|
|||
message_factory = MessageFactory.new
|
||||
client = LoginClient.new
|
||||
|
||||
login_ack = message_factory.login_ack("127.0.0.1", client_id, user.remember_token, 15)
|
||||
login_ack = message_factory.login_ack("127.0.0.1", client_id, user.remember_token, 15, nil)
|
||||
|
||||
router.should_receive(:send_to_client).with(client, login_ack)
|
||||
router.should_receive(:extract_ip).at_least(:once).with(client).and_return("127.0.0.1")
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@ require 'evented-spec'
|
|||
jamenv = ENV['JAMENV']
|
||||
jamenv ||= 'development'
|
||||
|
||||
config = YAML::load(File.open('config/application.yml'))[jamenv]
|
||||
fn = "#{File.dirname(__FILE__)}/../config/application.yml"
|
||||
puts "*** spec_helper.rb: fn=#{fn}; #{File.exists?(fn)}; #{jamenv}"
|
||||
|
||||
ff = File.open("#{File.dirname(__FILE__)}/../config/application.yml",'r')
|
||||
config = YAML::load(ff)[jamenv]
|
||||
puts "*** spec_helper.rb: jamenv=#{jamenv}; config = #{config}"
|
||||
|
||||
if config["verbose"]
|
||||
Logging.logger.root.level = :debug
|
||||
|
|
|
|||
Loading…
Reference in New Issue