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

thing. use built in resque inline method for single process mode
This commit is contained in:
Maxwell Salzberg 2011-07-02 11:55:41 -07:00
parent 7f55279962
commit dd752d7dd9
27 changed files with 34 additions and 44 deletions

View file

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

View file

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

View file

@ -1,16 +1,5 @@
module Job
class Base
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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,7 +8,7 @@ module Job
require File.join(Rails.root, 'lib/postzord/receiver')
@queue = :receive
def self.perform_delegate(post_id, recipient_user_ids)
def self.perform(post_id, recipient_user_ids)
post = Post.find(post_id)
create_visibilities(post, recipient_user_ids)
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
@queue = :receive_salmon
def self.perform_delegate(user_id, xml)
def self.perform(user_id, xml)
user = User.find(user_id)
zord = Postzord::Receiver.new(user, :salmon_xml => xml)
zord.perform

View file

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

View file

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

View file

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

View file

@ -8,12 +8,7 @@ begin
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
Resque.inline = true
end
rescue
nil

View file

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

View file

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

View file

@ -9,18 +9,18 @@ describe Job::ReceiveLocalBatch do
@post = alice.build_post(:status_message, :text => 'Hey Bob')
@post.save!
end
describe '.perform_delegate' do
describe '.perform' do
it 'calls .create_visibilities' do
Job::ReceiveLocalBatch.should_receive(:create_visibilities).with(@post, [bob.id])
Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
Job::ReceiveLocalBatch.perform(@post.id, [bob.id])
end
it 'sockets to users' do
Job::ReceiveLocalBatch.should_receive(:socket_to_users).with(@post, [bob.id])
Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
Job::ReceiveLocalBatch.perform(@post.id, [bob.id])
end
it 'notifies mentioned users' do
Job::ReceiveLocalBatch.should_receive(:notify_mentioned_users).with(@post)
Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
Job::ReceiveLocalBatch.perform(@post.id, [bob.id])
end
end
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))
Invitation.stub(:where).with(:id => invitation.id ).and_return([invitation])
invitation.should_receive(:resend)
Job::ResendInvitation.perform_delegate(invitation.id)
Job::ResendInvitation.perform(invitation.id)
end
end
end