From 8821043ed7197903f628352f33e3adfa09c1ea79 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 17:47:27 -0700 Subject: [PATCH 1/3] work in process --- config/environments/development.rb | 3 +++ config/environments/production.rb | 4 ++++ config/initializers/resque.rb | 13 +++++++++++-- script/server | 1 - 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 0051d171d..8329de4eb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -23,6 +23,9 @@ Diaspora::Application.configure do config.active_support.deprecation = :log #config.threadsafe! + # Process jobs in process? + config.work_in_process = true + # Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars # This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why # Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls diff --git a/config/environments/production.rb b/config/environments/production.rb index f02ea6132..d38457c5b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,6 +47,10 @@ Diaspora::Application.configure do # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true config.threadsafe! + + # Process jobs in process? + #config.work_in_process = false + end # Sacrifice readability for a 10% performance boost diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 94fe55ac4..48336f818 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -1,5 +1,14 @@ require File.join(Rails.root, 'app', 'models', 'jobs', 'base') Dir[File.join(Rails.root, 'app', 'models', 'jobs', '*.rb')].each { |file| require file } -#config = YAML::load(File.open("#{Rails.root}/config/redis.yml")) -#Resque.redis = Redis.new(:host => config['host'], :port => config['port']) + require 'resque' + +begin + if Diaspora::Application.config.work_in_process + module Resque + def enqueue(klass, *args) + klass.send(:perform, *args) + end + end + end +end diff --git a/script/server b/script/server index f2a2d2843..d94da6d15 100755 --- a/script/server +++ b/script/server @@ -121,7 +121,6 @@ if [ -n "$services" ]; then exit 64 fi - redis_config From 55d39521c4e6042a1f81755ca92f63e839bc7520 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 18:29:31 -0700 Subject: [PATCH 2/3] rescue redis connection attempts in websocket --- config/initializers/resque.rb | 6 ++++++ lib/diaspora/web_socket.rb | 12 ++++++++++-- spec/lib/diaspora/web_socket_spec.rb | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 48336f818..22be0cec2 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -5,10 +5,16 @@ require 'resque' begin if Diaspora::Application.config.work_in_process + if Rails.env == 'production' + puts "WARNING: You are running Diaspora in production without Resque workers turned on. Please don't do this." + end + module Resque def enqueue(klass, *args) klass.send(:perform, *args) end end end +rescue + nil end diff --git a/lib/diaspora/web_socket.rb b/lib/diaspora/web_socket.rb index f27527ca8..9df317df2 100644 --- a/lib/diaspora/web_socket.rb +++ b/lib/diaspora/web_socket.rb @@ -60,11 +60,19 @@ module Diaspora module Socketable def socket_to_user(user_or_id, opts={}) - SocketsController.new.outgoing(user_or_id, self, opts) + begin + SocketsController.new.outgoing(user_or_id, self, opts) + rescue + nil + end end def unsocket_from_user(user_or_id, opts={}) - SocketsController.new.outgoing(user_or_id, Retraction.for(self), opts) + begin + SocketsController.new.outgoing(user_or_id, Retraction.for(self), opts) + rescue + nil + end end end end diff --git a/spec/lib/diaspora/web_socket_spec.rb b/spec/lib/diaspora/web_socket_spec.rb index 551b874d0..37fda4e68 100644 --- a/spec/lib/diaspora/web_socket_spec.rb +++ b/spec/lib/diaspora/web_socket_spec.rb @@ -63,4 +63,11 @@ describe Diaspora::Socketable do Diaspora::WebSocket.should_receive(:queue_to_user) @post.socket_to_user(@user, :aspect_ids => @aspect.id) end + + it 'no-ops if redis isnt present' do + Diaspora::WebSocket.stub(:redis).and_return(nil) + lambda { + @post.socket_to_user(@user, :aspect_ids => @aspect.id) + }.should_not raise_error + end end From 7042b43799b32023043c764d9f2045989a5e00e9 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 May 2011 18:54:50 -0700 Subject: [PATCH 3/3] use appconfig instead of config --- config/app_config.yml.example | 4 ++++ config/environments/development.rb | 3 --- config/environments/production.rb | 4 ---- config/initializers/resque.rb | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 8d3c1ec47..393b6e53d 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -96,6 +96,9 @@ default: # It is false by default in development and test. enable_splunk_logging: true + # Process jobs in process? + single_process_mode: true + development: enable_splunk_logging: false @@ -105,3 +108,4 @@ test: enable_splunk_logging: false production: + single_process_mode: false diff --git a/config/environments/development.rb b/config/environments/development.rb index 8329de4eb..0051d171d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -23,9 +23,6 @@ Diaspora::Application.configure do config.active_support.deprecation = :log #config.threadsafe! - # Process jobs in process? - config.work_in_process = true - # Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars # This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why # Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls diff --git a/config/environments/production.rb b/config/environments/production.rb index d38457c5b..f02ea6132 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,10 +47,6 @@ Diaspora::Application.configure do # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true config.threadsafe! - - # Process jobs in process? - #config.work_in_process = false - end # Sacrifice readability for a 10% performance boost diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index 22be0cec2..cc977ba6a 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -4,7 +4,7 @@ Dir[File.join(Rails.root, 'app', 'models', 'jobs', '*.rb')].each { |file| requir require 'resque' begin - if Diaspora::Application.config.work_in_process + if AppConfig[:single_process_mode] if Rails.env == 'production' puts "WARNING: You are running Diaspora in production without Resque workers turned on. Please don't do this." end