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/initializers/resque.rb b/config/initializers/resque.rb index 94fe55ac4..cc977ba6a 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -1,5 +1,20 @@ 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 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 + + 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/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 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