Revert "remove perform delegate: use a gem that unobtrusivly does the same"

the connection adapter messes with single process mode...
This reverts commit dd752d7dd9.
This commit is contained in:
Maxwell Salzberg 2011-07-02 12:01:31 -07:00
parent dd752d7dd9
commit 696779d589
27 changed files with 44 additions and 34 deletions

View file

@ -58,7 +58,6 @@ gem "excon", "0.2.4"
gem 'mini_magick', '3.2' gem 'mini_magick', '3.2'
gem 'aws', '2.3.32' # upgrade to 2.4 breaks 1.8 >.< gem 'aws', '2.3.32' # upgrade to 2.4 breaks 1.8 >.<
gem 'fastercsv', '1.5.4', :require => false gem 'fastercsv', '1.5.4', :require => false
gem 'jammit', '0.5.4' gem 'jammit', '0.5.4'
gem 'rest-client', '1.6.1' gem 'rest-client', '1.6.1'
@ -71,7 +70,6 @@ gem 'cloudfiles', '1.4.10', :require => false
#Queue #Queue
gem 'resque', '1.10.0' gem 'resque', '1.10.0'
gem 'resque-ensure-connected'
gem 'SystemTimer', '1.2.1', :platforms => :ruby_18 gem 'SystemTimer', '1.2.1', :platforms => :ruby_18
group :development do group :development do

View file

@ -351,9 +351,6 @@ GEM
redis-namespace (~> 0.8.0) redis-namespace (~> 0.8.0)
sinatra (>= 0.9.2) sinatra (>= 0.9.2)
vegas (~> 0.1.2) vegas (~> 0.1.2)
resque-ensure-connected (0.1.0)
activerecord (>= 2.3.5)
resque (~> 1.10.0)
rest-client (1.6.1) rest-client (1.6.1)
mime-types (>= 1.16) mime-types (>= 1.16)
rspec (2.6.0) rspec (2.6.0)
@ -490,7 +487,6 @@ DEPENDENCIES
rails (= 3.0.3) rails (= 3.0.3)
rcov rcov
resque (= 1.10.0) resque (= 1.10.0)
resque-ensure-connected
rest-client (= 1.6.1) rest-client (= 1.6.1)
roxml! roxml!
rspec (>= 2.0.0) rspec (>= 2.0.0)

View file

@ -1,5 +1,16 @@
module Job module Job
class Base class Base
extend ResqueJobLogging extend ResqueJobLogging
# Perform this job. This wrapper method
def self.perform(*args)
ActiveRecord::Base.verify_active_connections!
self.perform_delegate(*args)
end
# Override this in your Job class.
# @abstract
def self.perform_delegate(*args)
end
end end
end end

View file

@ -6,7 +6,7 @@
module Job module Job
class DeleteAccount < Base class DeleteAccount < Base
@queue = :delete_account @queue = :delete_account
def self.perform(user_id) def self.perform_delegate(user_id)
user = User.find(user_id) user = User.find(user_id)
user.remove_all_traces user.remove_all_traces
user.destroy user.destroy

View file

@ -13,7 +13,7 @@ module Job
MAX_RETRIES = 3 MAX_RETRIES = 3
OPTS = {:max_redirects => 3, :timeout => 5000, :method => :post} OPTS = {:max_redirects => 3, :timeout => 5000, :method => :post}
def self.perform(user_id, enc_object_xml, person_ids, retry_count=0) def self.perform_delegate(user_id, enc_object_xml, person_ids, retry_count=0)
user = User.find(user_id) user = User.find(user_id)
people = Person.where(:id => person_ids) people = Person.where(:id => person_ids)

View file

@ -8,7 +8,7 @@ module Job
@queue = :http @queue = :http
NUM_TRIES = 3 NUM_TRIES = 3
def self.perform(url, body, tries_remaining = NUM_TRIES) def self.perform_delegate(url, body, tries_remaining = NUM_TRIES)
begin begin
body = CGI::escape(body) body = CGI::escape(body)
RestClient.post(url, :xml => body){ |response, request, result, &block| RestClient.post(url, :xml => body){ |response, request, result, &block|

View file

@ -6,7 +6,7 @@
module Job module Job
class InviteUserByEmail < Base class InviteUserByEmail < Base
@queue = :mail @queue = :mail
def self.perform(sender_id, email, aspect_id, invite_message) def self.perform_delegate(sender_id, email, aspect_id, invite_message)
user = User.find(sender_id) user = User.find(sender_id)
user.invite_user(aspect_id, 'email', email, invite_message) user.invite_user(aspect_id, 'email', email, invite_message)
end end

View file

@ -1,7 +1,7 @@
module Job module Job
class MailAlsoCommented < Base class MailAlsoCommented < Base
@queue = :mail @queue = :mail
def self.perform(recipient_id, sender_id, comment_id) def self.perform_delegate(recipient_id, sender_id, comment_id)
Notifier.also_commented(recipient_id, sender_id, comment_id).deliver Notifier.also_commented(recipient_id, sender_id, comment_id).deliver
end end
end end

View file

@ -1,7 +1,7 @@
module Job module Job
class MailCommentOnPost < Base class MailCommentOnPost < Base
@queue = :mail @queue = :mail
def self.perform(recipient_id, sender_id, comment_id) def self.perform_delegate(recipient_id, sender_id, comment_id)
Notifier.comment_on_post(recipient_id, sender_id, comment_id).deliver Notifier.comment_on_post(recipient_id, sender_id, comment_id).deliver
end end
end end

View file

@ -1,7 +1,7 @@
module Job module Job
class MailLiked < Base class MailLiked < Base
@queue = :mail @queue = :mail
def self.perform(recipient_id, sender_id, like_id) def self.perform_delegate(recipient_id, sender_id, like_id)
Notifier.liked(recipient_id, sender_id, like_id).deliver Notifier.liked(recipient_id, sender_id, like_id).deliver
end end
end end

View file

@ -6,7 +6,7 @@
module Job module Job
class MailMentioned < Base class MailMentioned < Base
@queue = :mail @queue = :mail
def self.perform(recipient_id, actor_id, target_id) def self.perform_delegate(recipient_id, actor_id, target_id)
Notifier.mentioned( recipient_id, actor_id, target_id).deliver Notifier.mentioned( recipient_id, actor_id, target_id).deliver

View file

@ -6,7 +6,7 @@
module Job module Job
class MailPrivateMessage < Base class MailPrivateMessage < Base
@queue = :mail @queue = :mail
def self.perform(recipient_id, actor_id, target_id) def self.perform_delegate(recipient_id, actor_id, target_id)
Notifier.private_message( recipient_id, actor_id, target_id).deliver Notifier.private_message( recipient_id, actor_id, target_id).deliver
end end
end end

View file

@ -6,7 +6,7 @@
module Job module Job
class MailStartedSharing < Base class MailStartedSharing < Base
@queue = :mail @queue = :mail
def self.perform(recipient_id, sender_id, target_id) def self.perform_delegate(recipient_id, sender_id, target_id)
Notifier.started_sharing(recipient_id, sender_id).deliver Notifier.started_sharing(recipient_id, sender_id).deliver
end end
end end

View file

@ -8,7 +8,7 @@ module Job
require File.join(Rails.root, 'app/models/notification') require File.join(Rails.root, 'app/models/notification')
def self.perform(user_ids, object_klass, object_id, person_id) def self.perform_delegate(user_ids, object_klass, object_id, person_id)
users = User.where(:id => user_ids) users = User.where(:id => user_ids)
object = object_klass.constantize.find_by_id(object_id) object = object_klass.constantize.find_by_id(object_id)
person = Person.find_by_id(person_id) person = Person.find_by_id(person_id)

View file

@ -6,7 +6,7 @@ module Job
class PostToService < Base class PostToService < Base
@queue = :http_service @queue = :http_service
def self.perform(service_id, post_id, url) def self.perform_delegate(service_id, post_id, url)
service = Service.find_by_id(service_id) service = Service.find_by_id(service_id)
post = Post.find_by_id(post_id) post = Post.find_by_id(post_id)
service.post(post, url) service.post(post, url)

View file

@ -6,7 +6,7 @@
module Job module Job
class ProcessPhoto < Base class ProcessPhoto < Base
@queue = :photos @queue = :photos
def self.perform(photo_id) def self.perform_delegate(photo_id)
Photo.find(photo_id).process Photo.find(photo_id).process
end end
end end

View file

@ -6,7 +6,7 @@ module Job
class PublishToHub < Base class PublishToHub < Base
@queue = :http_service @queue = :http_service
def self.perform(sender_public_url) def self.perform_delegate(sender_public_url)
require File.join(Rails.root, 'lib/pubsubhubbub') require File.join(Rails.root, 'lib/pubsubhubbub')
atom_url = sender_public_url + '.atom' atom_url = sender_public_url + '.atom'
Pubsubhubbub.new(AppConfig[:pubsub_server]).publish(atom_url) Pubsubhubbub.new(AppConfig[:pubsub_server]).publish(atom_url)

View file

@ -8,7 +8,7 @@ module Job
require File.join(Rails.root, 'lib/postzord/receiver') require File.join(Rails.root, 'lib/postzord/receiver')
@queue = :receive @queue = :receive
def self.perform(post_id, recipient_user_ids) def self.perform_delegate(post_id, recipient_user_ids)
post = Post.find(post_id) post = Post.find(post_id)
create_visibilities(post, recipient_user_ids) create_visibilities(post, recipient_user_ids)
socket_to_users(post, recipient_user_ids) if post.respond_to?(:socket_to_user) socket_to_users(post, recipient_user_ids) if post.respond_to?(:socket_to_user)

View file

@ -8,7 +8,7 @@ module Job
class ReceiveSalmon < Base class ReceiveSalmon < Base
@queue = :receive_salmon @queue = :receive_salmon
def self.perform(user_id, xml) def self.perform_delegate(user_id, xml)
user = User.find(user_id) user = User.find(user_id)
zord = Postzord::Receiver.new(user, :salmon_xml => xml) zord = Postzord::Receiver.new(user, :salmon_xml => xml)
zord.perform zord.perform

View file

@ -6,7 +6,7 @@
module Job module Job
class ResendInvitation < Base class ResendInvitation < Base
@queue = :mail @queue = :mail
def self.perform(invitation_id) def self.perform_delegate(invitation_id)
inv = Invitation.where(:id => invitation_id).first inv = Invitation.where(:id => invitation_id).first
inv.resend inv.resend
end end

View file

@ -8,7 +8,7 @@ module Job
@queue = :socket_webfinger @queue = :socket_webfinger
def self.perform(user_id, account, opts={}) def self.perform_delegate(user_id, account, opts={})
finger = Webfinger.new(account) finger = Webfinger.new(account)
begin begin
result = finger.fetch result = finger.fetch

View file

@ -6,7 +6,7 @@
module Job module Job
class UpdateServiceUsers < Base class UpdateServiceUsers < Base
@queue = :http_service @queue = :http_service
def self.perform(service_id) def self.perform_delegate(service_id)
service = Service.find(service_id) service = Service.find(service_id)
service.save_friends service.save_friends
end end

View file

@ -8,7 +8,12 @@ begin
if Rails.env == 'production' if Rails.env == 'production'
puts "WARNING: You are running Diaspora in production without Resque workers turned on. Please don't do this." puts "WARNING: You are running Diaspora in production without Resque workers turned on. Please don't do this."
end end
Resque.inline = true
module Resque
def enqueue(klass, *args)
klass.send(:perform, *args)
end
end
end end
rescue rescue
nil nil

View file

@ -5,7 +5,7 @@
require 'spec_helper' require 'spec_helper'
describe Job::MailMentioned do describe Job::MailMentioned do
describe '#perfom' do describe '#perfom_delegate' do
it 'should call .deliver on the notifier object' do it 'should call .deliver on the notifier object' do
user = alice user = alice
sm = Factory(:status_message) sm = Factory(:status_message)
@ -15,7 +15,7 @@ describe Job::MailMentioned do
mail_mock.should_receive(:deliver) mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_mock) Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_mock)
Job::MailMentioned.perform(user.id, sm.author.id, m.id) Job::MailMentioned.perform_delegate(user.id, sm.author.id, m.id)
end end
end end
end end

View file

@ -21,7 +21,7 @@ describe Job::MailPrivateMessage do
mail_mock.should_receive(:deliver) mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_mock) Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_mock)
Job::MailMentioned.perform(user2.id, user1.person.id, message.id) Job::MailMentioned.perform_delegate(user2.id, user1.person.id, message.id)
end end
end end
end end

View file

@ -9,18 +9,18 @@ describe Job::ReceiveLocalBatch do
@post = alice.build_post(:status_message, :text => 'Hey Bob') @post = alice.build_post(:status_message, :text => 'Hey Bob')
@post.save! @post.save!
end end
describe '.perform' do describe '.perform_delegate' do
it 'calls .create_visibilities' do it 'calls .create_visibilities' do
Job::ReceiveLocalBatch.should_receive(:create_visibilities).with(@post, [bob.id]) Job::ReceiveLocalBatch.should_receive(:create_visibilities).with(@post, [bob.id])
Job::ReceiveLocalBatch.perform(@post.id, [bob.id]) Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
end end
it 'sockets to users' do it 'sockets to users' do
Job::ReceiveLocalBatch.should_receive(:socket_to_users).with(@post, [bob.id]) Job::ReceiveLocalBatch.should_receive(:socket_to_users).with(@post, [bob.id])
Job::ReceiveLocalBatch.perform(@post.id, [bob.id]) Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
end end
it 'notifies mentioned users' do it 'notifies mentioned users' do
Job::ReceiveLocalBatch.should_receive(:notify_mentioned_users).with(@post) Job::ReceiveLocalBatch.should_receive(:notify_mentioned_users).with(@post)
Job::ReceiveLocalBatch.perform(@post.id, [bob.id]) Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
end end
end end
describe '.create_visibilities' do describe '.create_visibilities' do

View file

@ -15,7 +15,7 @@ describe Job::ResendInvitation do
#Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)) #Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person))
Invitation.stub(:where).with(:id => invitation.id ).and_return([invitation]) Invitation.stub(:where).with(:id => invitation.id ).and_return([invitation])
invitation.should_receive(:resend) invitation.should_receive(:resend)
Job::ResendInvitation.perform(invitation.id) Job::ResendInvitation.perform_delegate(invitation.id)
end end
end end
end end