Move notifying iteration into resque job

This commit is contained in:
Raphael Sofaer 2011-03-17 15:19:12 -07:00
parent 43fc2c4d63
commit bef06d18d8
3 changed files with 7 additions and 10 deletions

View file

@ -8,12 +8,12 @@ module Job
require File.join(Rails.root, 'app/models/notification')
def self.perform_delegate(user_id, object_klass, object_id, person_id)
user = User.find_by_id(user_id)
def self.perform_delegate(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)
Notification.notify(user, object, person)
users.each{|user| Notification.notify(user, object, person) }
end
end
end

View file

@ -83,9 +83,7 @@ class Postzord::Dispatch
end
def notify_users(users)
users.each do |user|
Resque.enqueue(Job::NotifyLocalUsers, user.id, @object.class.to_s, @object.id, @object.author.id)
end
Resque.enqueue(Job::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id)
end
def socket_to_users(users)
return unless @object.respond_to?(:socket_to_user)

View file

@ -6,13 +6,12 @@ require 'spec_helper'
describe Job::NotifyLocalUsers do
describe '#perfom' do
it 'should call Notification.notify on the object' do
user = alice
it 'should call Notification.notify for each user' do
person = Factory :person
object = Factory :status_message
Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person))
Job::NotifyLocalUsers.perform(user.id, object.class.to_s, object.id, person.id)
Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)).twice
Job::NotifyLocalUsers.perform([alice.id, eve.id], object.class.to_s, object.id, person.id)
end
end
end