From bea76a48013dab4a13ca9d815d8eabaab9b6a745 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Fri, 9 Sep 2011 08:57:56 -0700 Subject: [PATCH] move the ugly type check into the ugly method, to keep all the ugly in one place; restore listening to single process mode in resque; move the exception handling to inside the method, rather than around the intializer, and log when resque errors happen in development in single process mode --- app/models/notification.rb | 5 ++++- config/initializers/resque.rb | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 277903e2e..fbaaf5390 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -68,7 +68,7 @@ private def self.make_notification(recipient, target, actor, notification_type) - return nil if target.is_a?(Post) && post_visiblity_is_hidden?(recipient, target) + return nil if post_visiblity_is_hidden?(recipient, target) n = notification_type.new(:target => target, :recipient_id => recipient.id) n.actors = n.actors | [actor] @@ -77,7 +77,10 @@ private n end + #horrible hack that should not be here! def self.post_visiblity_is_hidden?(recipient, post) + return false unless post.is_a?(Post) + contact = recipient.contact_for(post.author) return false unless contact && recipient && post pv = PostVisibility.where(:contact_id => contact.id, :post_id => post.id).first diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index f68fe73ec..af6f820b8 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -6,17 +6,18 @@ if !ENV['SINGLE_PROCESS'] && AppConfig[:redis_url] Resque.redis = Redis.new(:host => AppConfig[:redis_url], :port => 6379) end -begin - if ENV['SINGLE_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) +if ENV['SINGLE_PROCESS'] || 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) + begin klass.send(:perform, *args) + rescue Exception => e + Rails.logger(e.message) + nil end end end -rescue - nil end