* fix startup of eventmachine when in unicorn/production mode (fixes or could fix: VRFS-1636 VRFS-1637 VRFS-1642 VRFS-1643

This commit is contained in:
Seth Call 2014-04-23 15:08:19 +00:00
parent 5b92445021
commit 29dfba8276
4 changed files with 21 additions and 9 deletions

View File

@ -36,7 +36,7 @@ module JamWebEventMachine
end
def self.run_em(calling_thread)
def self.run_em(calling_thread = nil)
EM.run do
# this is global because we need to check elsewhere if we are currently connected to amqp before signalling success with some APIs, such as 'create session'
@ -54,7 +54,7 @@ module JamWebEventMachine
end
end
calling_thread.wakeup
calling_thread.wakeup if calling_thread
end
end

View File

@ -55,6 +55,7 @@ class MQRouter
# sends a message to a client with no checking of permissions (RAW USAGE)
# this method deliberately has no database interactivity/active_record objects
def publish_to_client(client_id, client_msg, sender = {:client_id => ""})
@@log.error "EM not running in publish_to_client" unless EM.reactor_running?
EM.schedule do
sender_client_id = sender[:client_id]
@ -68,6 +69,7 @@ class MQRouter
# sends a message to a session with no checking of permissions (RAW USAGE)
# this method deliberately has no database interactivity/active_record objects
def publish_to_session(music_session_id, client_ids, client_msg, sender = {:client_id => nil})
@@log.error "EM not running in publish_to_session" unless EM.reactor_running?
EM.schedule do
sender_client_id = sender[:client_id]
@ -84,7 +86,7 @@ class MQRouter
# sends a message to a user with no checking of permissions (RAW USAGE)
# this method deliberately has no database interactivity/active_record objects
def publish_to_user(user_id, user_msg)
@@log.warn "EM not running in publish_to_user" unless EM.reactor_running?
@@log.error "EM not running in publish_to_user" unless EM.reactor_running?
EM.schedule do
@@log.debug "publishing to user:#{user_id} from server"
@ -96,6 +98,8 @@ class MQRouter
# sends a message to a list of friends with no checking of permissions (RAW USAGE)
# this method deliberately has no database interactivity/active_record objects
def publish_to_friends(friend_ids, user_msg, from_user_id)
@@log.error "EM not running in publish_to_friends" unless EM.reactor_running?
EM.schedule do
friend_ids.each do |friend_id|
@@log.debug "publishing to friend:#{friend_id} from user/band #{from_user_id}"

View File

@ -22,5 +22,9 @@
.buttons {
margin:0 20px 20px 0;
}
.close-btn {
display:none;
}
}

View File

@ -17,11 +17,11 @@ worker_processes 4
# as root unless it's from system init scripts.
# If running the master process as root and the workers as an unprivileged
# user, do this to switch euid/egid in the workers (also chowns logs):
user "jam-web", "jam-web"
#user "jam-web", "jam-web"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/var/lib/jam-web" # available in 0.94.0+
#working_directory "/var/lib/jam-web" # available in 0.94.0+
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
@ -32,13 +32,13 @@ listen 3100, :tcp_nopush => true
timeout 30
# feel free to point this anywhere accessible on the filesystem
pid "/var/run/jam-web/jam-web.pid"
#pid "/var/run/jam-web/jam-web.pid"
# By default, the Unicorn logger will write to stderr.
# Additionally, ome applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path "/var/lib/jam-web/log/unicorn.stderr.log"
stdout_path "/var/lib/jam-web/log/unicorn.stdout.log"
#stderr_path "/var/lib/jam-web/log/unicorn.stderr.log"
#stdout_path "/var/lib/jam-web/log/unicorn.stdout.log"
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
@ -95,7 +95,11 @@ after_fork do |server, worker|
ActiveRecord::Base.establish_connection
Thread.new do
JamWebEventMachine.run_em
begin
JamWebEventMachine.run_em
rescue Exception => e
puts "unable to start eventmachine in after_fork!!: #{e}"
end
end
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,