From cd16c76f569e0363a7681d5581241dd315339e45 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 6 Feb 2013 07:00:51 -0600 Subject: [PATCH 1/3] vrfs 192: added max_reconnect_time variable; added aasm/thin gems; integrated connection.aasm_state into participant REST --- Gemfile | 2 ++ app/views/api_music_sessions/participant_show.rabl | 2 ++ app/views/api_music_sessions/show.rabl | 2 +- config/application.rb | 3 ++- config/environments/cucumber.rb | 1 + config/initializers/websocket_gateway.rb | 5 +++-- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index bd4b834d8..f7f37096a 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ if devenv gem 'jampb', :path => "#{workspace}/jam-pb/target/ruby/jampb" gem 'jam_ruby', :path => "#{workspace}/jam-ruby" gem 'jam_websockets', :path => "#{workspace}/websocket-gateway" + gem 'thin' else gem 'jam_db' gem 'jampb' @@ -43,6 +44,7 @@ gem 'sendgrid', '1.1.0' gem 'recaptcha', '0.3.4' gem 'filepicker-rails', '0.0.2' gem 'aws-sdk', '1.8.0' +gem 'aasm', '3.0.16' #group :libv8 do # gem 'libv8', "~> 3.11.8" diff --git a/app/views/api_music_sessions/participant_show.rabl b/app/views/api_music_sessions/participant_show.rabl index 307a3021d..cbbf29c87 100644 --- a/app/views/api_music_sessions/participant_show.rabl +++ b/app/views/api_music_sessions/participant_show.rabl @@ -1,6 +1,8 @@ object @connection attributes :ip_address, :client_id +attribute :aasm_state => :connection_state + node(:user_id, :if => lambda { |connection| connection.user.friends?(current_user) }) do |connection| connection.user_id end diff --git a/app/views/api_music_sessions/show.rabl b/app/views/api_music_sessions/show.rabl index 9a2efe33c..0f6ce7b57 100644 --- a/app/views/api_music_sessions/show.rabl +++ b/app/views/api_music_sessions/show.rabl @@ -11,7 +11,7 @@ child(:connections => :participants) { attributes :ip_address, :client_id node :user do |connection| - { :id => connection.user.id, :photo_url => connection.user.photo_url, :name => connection.user.name, :is_friend => connection.user.friends?(current_user) } + { :id => connection.user.id, :photo_url => connection.user.photo_url, :name => connection.user.name, :is_friend => connection.user.friends?(current_user), :connection_state => connection.aasm_state } end child(:tracks => :tracks) { diff --git a/config/application.rb b/config/application.rb index 85c2191b3..9aaf214c4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -88,7 +88,8 @@ module SampleApp # Websocket-gateway embedded configs config.websocket_gateway_enable = false - config.websocket_gateway_max_stale_connection_time = 1800 + config.websocket_gateway_max_stale_connection_time = 300 + config.websocket_gateway_max_reconnect_time = 1800 config.websocket_gateway_internal_debug = false config.websocket_gateway_port = 6767 end diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index dd44e7246..b1916f4fc 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -51,6 +51,7 @@ SampleApp::Application.configure do # Websocket-gateway embedded configs config.websocket_gateway_enable = true config.websocket_gateway_max_stale_connection_time = 30 + config.websocket_gateway_max_reconnect_time = 180 config.websocket_gateway_internal_debug = false config.websocket_gateway_port = 6777 diff --git a/config/initializers/websocket_gateway.rb b/config/initializers/websocket_gateway.rb index 1a2745f29..4c87d4eea 100644 --- a/config/initializers/websocket_gateway.rb +++ b/config/initializers/websocket_gateway.rb @@ -2,5 +2,6 @@ if Rails.application.config.websocket_gateway_enable JamWebsockets::Server.new.run :port => Rails.application.config.websocket_gateway_port, :emwebsocket_debug => Rails.application.config.websocket_gateway_internal_debug, - :max_stale_connection_time => Rails.application.config.websocket_gateway_max_stale_connection_time -end \ No newline at end of file + :max_stale_connection_time => Rails.application.config.websocket_gateway_max_stale_connection_time, + :max_reconnect_time => Rails.application.config.websocket_gateway_max_reconnect_time +end From 5535b647567754e6aabe69df29683458d7313d46 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 11 Feb 2013 00:03:00 -0600 Subject: [PATCH 2/3] removed thin gem --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index f7f37096a..9d04219ca 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,6 @@ if devenv gem 'jampb', :path => "#{workspace}/jam-pb/target/ruby/jampb" gem 'jam_ruby', :path => "#{workspace}/jam-ruby" gem 'jam_websockets', :path => "#{workspace}/websocket-gateway" - gem 'thin' else gem 'jam_db' gem 'jampb' From f571de783fc423f772b178793de9f09494249d14 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 11 Feb 2013 00:03:47 -0600 Subject: [PATCH 3/3] renamed connection timers to correspond to state names --- config/application.rb | 4 ++-- config/environments/cucumber.rb | 4 ++-- config/initializers/eventmachine.rb | 1 + config/initializers/websocket_gateway.rb | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/application.rb b/config/application.rb index 9aaf214c4..6734cd331 100644 --- a/config/application.rb +++ b/config/application.rb @@ -88,8 +88,8 @@ module SampleApp # Websocket-gateway embedded configs config.websocket_gateway_enable = false - config.websocket_gateway_max_stale_connection_time = 300 - config.websocket_gateway_max_reconnect_time = 1800 + config.websocket_gateway_connect_time_stale = 30 + config.websocket_gateway_connect_time_expire = 180 config.websocket_gateway_internal_debug = false config.websocket_gateway_port = 6767 end diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index b1916f4fc..99814be3a 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -50,8 +50,8 @@ SampleApp::Application.configure do # Websocket-gateway embedded configs config.websocket_gateway_enable = true - config.websocket_gateway_max_stale_connection_time = 30 - config.websocket_gateway_max_reconnect_time = 180 + config.websocket_gateway_connect_time_stale = 30 + config.websocket_gateway_connect_time_expire = 180 config.websocket_gateway_internal_debug = false config.websocket_gateway_port = 6777 diff --git a/config/initializers/eventmachine.rb b/config/initializers/eventmachine.rb index e69884b6f..d1b84223b 100644 --- a/config/initializers/eventmachine.rb +++ b/config/initializers/eventmachine.rb @@ -31,6 +31,7 @@ module JamWebEventMachine end def self.die_gracefully_on_signal + Rails.logger.debug("*** die_gracefully_on_signal") Signal.trap("INT") { EM.stop } Signal.trap("TERM") { EM.stop } end diff --git a/config/initializers/websocket_gateway.rb b/config/initializers/websocket_gateway.rb index 4c87d4eea..ae8dabf47 100644 --- a/config/initializers/websocket_gateway.rb +++ b/config/initializers/websocket_gateway.rb @@ -2,6 +2,6 @@ if Rails.application.config.websocket_gateway_enable JamWebsockets::Server.new.run :port => Rails.application.config.websocket_gateway_port, :emwebsocket_debug => Rails.application.config.websocket_gateway_internal_debug, - :max_stale_connection_time => Rails.application.config.websocket_gateway_max_stale_connection_time, - :max_reconnect_time => Rails.application.config.websocket_gateway_max_reconnect_time + :connect_time_stale => Rails.application.config.websocket_gateway_connect_time_stale, + :connect_time_expire => Rails.application.config.websocket_gateway_connect_time_expire end