make jobs have a base class, which will verify the activerecord connection before trying the job
This commit is contained in:
parent
934f56b553
commit
e7a065a521
36 changed files with 111 additions and 110 deletions
|
|
@ -23,7 +23,7 @@ class InvitationsController < Devise::InvitationsController
|
||||||
|
|
||||||
good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}
|
good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}
|
||||||
|
|
||||||
good_emails.each{|e| Resque.enqueue(Jobs::InviteUser, current_user.id, e, aspect, message)}
|
good_emails.each{|e| Resque.enqueue(Job::InviteUser, current_user.id, e, aspect, message)}
|
||||||
|
|
||||||
if bad_emails.any?
|
if bad_emails.any?
|
||||||
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
|
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,6 @@ class PeopleController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
def webfinger(account, opts = {})
|
def webfinger(account, opts = {})
|
||||||
Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts)
|
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class PublicsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
@user = person.owner
|
@user = person.owner
|
||||||
Resque.enqueue(Jobs::ReceiveSalmon, @user.id, CGI::unescape(params[:xml]))
|
Resque.enqueue(Job::ReceiveSalmon, @user.id, CGI::unescape(params[:xml]))
|
||||||
|
|
||||||
render :nothing => true, :status => 200
|
render :nothing => true, :status => 200
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,4 @@ module AspectsHelper
|
||||||
end
|
end
|
||||||
(link_to str, '#', :id => 'expand_publisher').html_safe
|
(link_to str, '#', :id => 'expand_publisher').html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
13
app/models/jobs/base.rb
Normal file
13
app/models/jobs/base.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
module Job
|
||||||
|
class Base
|
||||||
|
extend ResqueJobLogging
|
||||||
|
|
||||||
|
def self.perform(*args)
|
||||||
|
ActiveRecord::Base.verify_active_connections!
|
||||||
|
self.perform_delegate(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.perform_delegate(*args) # override this
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -3,13 +3,12 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class HttpPost
|
class HttpPost < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class InviteUser
|
class InviteUser < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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(email, aspect_id, invite_message)
|
user.invite_user(email, aspect_id, invite_message)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
module Jobs
|
module Job
|
||||||
class MailAlsoCommented
|
class MailAlsoCommented < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
module Jobs
|
module Job
|
||||||
class MailCommentOnPost
|
class MailCommentOnPost < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class MailRequestAcceptance
|
class MailRequestAcceptance < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@queue = :mail
|
@queue = :mail
|
||||||
def self.perform(recipient_id, sender_id)
|
def self.perform_delegate(recipient_id, sender_id)
|
||||||
Notifier.request_accepted(recipient_id, sender_id).deliver
|
Notifier.request_accepted(recipient_id, sender_id).deliver
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class MailRequestReceived
|
class MailRequestReceived < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@queue = :mail
|
@queue = :mail
|
||||||
def self.perform(recipient_id, sender_id)
|
def self.perform_delegate(recipient_id, sender_id)
|
||||||
Notifier.new_request(recipient_id, sender_id).deliver
|
Notifier.new_request(recipient_id, sender_id).deliver
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,13 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class NotifyLocalUsers
|
class NotifyLocalUsers < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@queue = :receive_local
|
@queue = :receive_local
|
||||||
|
|
||||||
require File.join(Rails.root, 'app/models/notification')
|
require File.join(Rails.root, 'app/models/notification')
|
||||||
|
|
||||||
def self.perform(user_id, object_klass, object_id, person_id)
|
def self.perform_delegate(user_id, object_klass, object_id, person_id)
|
||||||
user = User.find_by_id(user_id)
|
user = User.find_by_id(user_id)
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
#
|
#
|
||||||
module Jobs
|
module Job
|
||||||
class PostToService
|
class PostToService < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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)
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class PostToServices
|
class PostToServices < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@queue = :http_service
|
@queue = :http_service
|
||||||
def self.perform(user_id, post_id, url)
|
def self.perform_delegate(user_id, post_id, url)
|
||||||
user = User.find_by_id(user_id)
|
user = User.find_by_id(user_id)
|
||||||
post = Post.find_by_id(post_id)
|
post = Post.find_by_id(post_id)
|
||||||
user.services.each do |s|
|
user.services.each do |s|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class PublishToHub
|
class PublishToHub < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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')
|
||||||
Pubsubhubbub.new(AppConfig[:pubsub_server]).publish(sender_public_url)
|
Pubsubhubbub.new(AppConfig[:pubsub_server]).publish(sender_public_url)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class Receive
|
class Receive < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@queue = :receive
|
@queue = :receive
|
||||||
def self.perform(user_id, xml, salmon_author_id)
|
def self.perform(user_id, xml, salmon_author_id)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class ReceiveLocal
|
class ReceiveLocal < Base
|
||||||
require File.join(Rails.root, 'lib/postzord/receiver')
|
require File.join(Rails.root, 'lib/postzord/receiver')
|
||||||
|
|
||||||
extend ResqueJobLogging
|
|
||||||
@queue = :receive_local
|
@queue = :receive_local
|
||||||
def self.perform(user_id, person_id, object_type, object_id)
|
def self.perform_delegate(user_id, person_id, object_type, object_id)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
person = Person.find(person_id)
|
person = Person.find(person_id)
|
||||||
object = object_type.constantize.where(:id => object_id).first
|
object = object_type.constantize.where(:id => object_id).first
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@
|
||||||
|
|
||||||
|
|
||||||
require File.join(Rails.root, 'lib/postzord/receiver')
|
require File.join(Rails.root, 'lib/postzord/receiver')
|
||||||
module Jobs
|
module Job
|
||||||
class ReceiveSalmon
|
class ReceiveSalmon < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
module Jobs
|
module Job
|
||||||
class SocketWebfinger
|
class SocketWebfinger < Base
|
||||||
extend ResqueJobLogging
|
|
||||||
@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
|
||||||
user = User.find_by_id(user_id)
|
user = User.find_by_id(user_id)
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,13 @@ class Notification < ActiveRecord::Base
|
||||||
def email_the_user
|
def email_the_user
|
||||||
case self.action
|
case self.action
|
||||||
when "new_request"
|
when "new_request"
|
||||||
self.recipient.mail(Jobs::MailRequestReceived, self.recipient_id, self.actor_id)
|
self.recipient.mail(Job::MailRequestReceived, self.recipient_id, self.actor_id)
|
||||||
when "request_accepted"
|
when "request_accepted"
|
||||||
self.recipient.mail(Jobs::MailRequestAcceptance, self.recipient_id, self.actor_id)
|
self.recipient.mail(Job::MailRequestAcceptance, self.recipient_id, self.actor_id)
|
||||||
when "comment_on_post"
|
when "comment_on_post"
|
||||||
self.recipient.mail(Jobs::MailCommentOnPost, self.recipient_id, self.actor_id, target.id)
|
self.recipient.mail(Job::MailCommentOnPost, self.recipient_id, self.actor_id, target.id)
|
||||||
when "also_commented"
|
when "also_commented"
|
||||||
self.recipient.mail(Jobs::MailAlsoCommented, self.recipient_id, self.actor_id, target.id)
|
self.recipient.mail(Job::MailAlsoCommented, self.recipient_id, self.actor_id, target.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,20 +41,20 @@ class Postzord::Dispatch
|
||||||
people.each do |person|
|
people.each do |person|
|
||||||
enc_xml = salmon.xml_for(person)
|
enc_xml = salmon.xml_for(person)
|
||||||
Rails.logger.info("event=deliver_to_remote route=remote sender=#{@sender.person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}")
|
Rails.logger.info("event=deliver_to_remote route=remote sender=#{@sender.person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}")
|
||||||
Resque.enqueue(Jobs::HttpPost, person.receive_url, enc_xml)
|
Resque.enqueue(Job::HttpPost, person.receive_url, enc_xml)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def deliver_to_local(people)
|
def deliver_to_local(people)
|
||||||
people.each do |person|
|
people.each do |person|
|
||||||
Rails.logger.info("event=push_to_local_person route=local sender=#{@sender_person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}")
|
Rails.logger.info("event=push_to_local_person route=local sender=#{@sender_person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}")
|
||||||
Resque.enqueue(Jobs::Receive, person.owner_id, @xml, @sender_person.id)
|
Resque.enqueue(Job::Receive, person.owner_id, @xml, @sender_person.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def deliver_to_hub
|
def deliver_to_hub
|
||||||
Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}")
|
Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}")
|
||||||
Resque.enqueue(Jobs::PublishToHub, @sender.public_url)
|
Resque.enqueue(Job::PublishToHub, @sender.public_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def deliver_to_services(url)
|
def deliver_to_services(url)
|
||||||
|
|
@ -62,7 +62,7 @@ class Postzord::Dispatch
|
||||||
deliver_to_hub
|
deliver_to_hub
|
||||||
if @object.respond_to?(:message)
|
if @object.respond_to?(:message)
|
||||||
@sender.services.each do |service|
|
@sender.services.each do |service|
|
||||||
Resque.enqueue(Jobs::PostToService, service.id, @object.id, url)
|
Resque.enqueue(Job::PostToService, service.id, @object.id, url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -74,7 +74,7 @@ class Postzord::Dispatch
|
||||||
if socket
|
if socket
|
||||||
@object.socket_to_user(user)
|
@object.socket_to_user(user)
|
||||||
end
|
end
|
||||||
Resque.enqueue(Jobs::NotifyLocalUsers, user.id, @object.class.to_s, @object.id, @sender_person.id)
|
Resque.enqueue(Job::NotifyLocalUsers, user.id, @object.class.to_s, @object.id, @sender_person.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ describe InvitationsController do
|
||||||
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
request.env["HTTP_REFERER"]= 'http://test.host/cats/foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls the resque job Jobs::InviteUser' do
|
it 'calls the resque job Job::InviteUser' do
|
||||||
Resque.should_receive(:enqueue)
|
Resque.should_receive(:enqueue)
|
||||||
post :create, :user => @invite
|
post :create, :user => @invite
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ describe PeopleController do
|
||||||
|
|
||||||
describe '#webfinger' do
|
describe '#webfinger' do
|
||||||
it 'enqueues a webfinger job' do
|
it 'enqueues a webfinger job' do
|
||||||
Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once
|
Resque.should_receive(:enqueue).with(Job::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once
|
||||||
get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
|
get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ describe PublicsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'enqueues a receive job' do
|
it 'enqueues a receive job' do
|
||||||
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, xml).once
|
Resque.should_receive(:enqueue).with(Job::ReceiveSalmon, @user.id, xml).once
|
||||||
post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
|
post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ describe PublicsController do
|
||||||
salmon_factory = Salmon::SalmonSlap.create(@user, xml2)
|
salmon_factory = Salmon::SalmonSlap.create(@user, xml2)
|
||||||
enc_xml = salmon_factory.xml_for(user2.person)
|
enc_xml = salmon_factory.xml_for(user2.person)
|
||||||
|
|
||||||
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, enc_xml).once
|
Resque.should_receive(:enqueue).with(Job::ReceiveSalmon, @user.id, enc_xml).once
|
||||||
post :receive, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
|
post :receive, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ describe Postzord::Dispatch do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should queue an HttpPost job for each remote person' do
|
it 'should queue an HttpPost job for each remote person' do
|
||||||
Resque.should_receive(:enqueue).with(Jobs::HttpPost, @user.person.receive_url, anything).once
|
Resque.should_receive(:enqueue).with(Job::HttpPost, @user.person.receive_url, anything).once
|
||||||
@mailman.send(:deliver_to_remote, @remote_people)
|
@mailman.send(:deliver_to_remote, @remote_people)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ describe Postzord::Dispatch do
|
||||||
local_people = []
|
local_people = []
|
||||||
local_people << @user.person
|
local_people << @user.person
|
||||||
mailman = Postzord::Dispatch.new(@user, @sm)
|
mailman = Postzord::Dispatch.new(@user, @sm)
|
||||||
Resque.should_receive(:enqueue).with(Jobs::Receive, @user.id, @xml, anything).once
|
Resque.should_receive(:enqueue).with(Job::Receive, @user.id, @xml, anything).once
|
||||||
mailman.send(:deliver_to_local, local_people)
|
mailman.send(:deliver_to_local, local_people)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -130,15 +130,15 @@ describe Postzord::Dispatch do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls post for each of the users services' do
|
it 'calls post for each of the users services' do
|
||||||
Resque.stub!(:enqueue).with(Jobs::PublishToHub, anything)
|
Resque.stub!(:enqueue).with(Job::PublishToHub, anything)
|
||||||
Resque.should_receive(:enqueue).with(Jobs::PostToService, @service.id, anything, anything).once
|
Resque.should_receive(:enqueue).with(Job::PostToService, @service.id, anything, anything).once
|
||||||
@zord.instance_variable_get(:@sender).should_receive(:services).and_return([@service])
|
@zord.instance_variable_get(:@sender).should_receive(:services).and_return([@service])
|
||||||
@zord.send(:deliver_to_services, nil)
|
@zord.send(:deliver_to_services, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'queues a job to notify the hub' do
|
it 'queues a job to notify the hub' do
|
||||||
Resque.stub!(:enqueue).with(Jobs::PostToService, anything, anything, anything)
|
Resque.stub!(:enqueue).with(Job::PostToService, anything, anything, anything)
|
||||||
Resque.should_receive(:enqueue).with(Jobs::PublishToHub, @user.public_url)
|
Resque.should_receive(:enqueue).with(Job::PublishToHub, @user.public_url)
|
||||||
@zord.send(:deliver_to_services, nil)
|
@zord.send(:deliver_to_services, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -166,9 +166,9 @@ describe Postzord::Dispatch do
|
||||||
z.send(:socket_and_notify_users, users)
|
z.send(:socket_and_notify_users, users)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'queues a Jobs::NotifyLocalUsers jobs' do
|
it 'queues a Job::NotifyLocalUsers jobs' do
|
||||||
@zord.instance_variable_get(:@object).should_receive(:socket_to_user).and_return(false)
|
@zord.instance_variable_get(:@object).should_receive(:socket_to_user).and_return(false)
|
||||||
Resque.should_receive(:enqueue).with(Jobs::NotifyLocalUsers, @local_user.id, @sm.class.to_s, @sm.id, anything)
|
Resque.should_receive(:enqueue).with(Job::NotifyLocalUsers, @local_user.id, @sm.class.to_s, @sm.id, anything)
|
||||||
@zord.send(:socket_and_notify_users, [@local_user])
|
@zord.send(:socket_and_notify_users, [@local_user])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::HttpPost do
|
describe Job::HttpPost do
|
||||||
before do
|
before do
|
||||||
@url = 'example.org/things/on/fire'
|
@url = 'example.org/things/on/fire'
|
||||||
@body = '<xml>California</xml>'
|
@body = '<xml>California</xml>'
|
||||||
|
|
@ -8,11 +8,11 @@ describe Jobs::HttpPost do
|
||||||
end
|
end
|
||||||
it 'POSTs to a given URL' do
|
it 'POSTs to a given URL' do
|
||||||
RestClient.should_receive(:post).with(@url, {:xml=>@escaped_body}).and_return(true)
|
RestClient.should_receive(:post).with(@url, {:xml=>@escaped_body}).and_return(true)
|
||||||
Jobs::HttpPost.perform(@url, @body, 3)
|
Job::HttpPost.perform(@url, @body, 3)
|
||||||
end
|
end
|
||||||
it 'retries' do
|
it 'retries' do
|
||||||
RestClient.should_receive(:post).with(@url, {:xml=>@escaped_body}).and_raise(SocketError)
|
RestClient.should_receive(:post).with(@url, {:xml=>@escaped_body}).and_raise(SocketError)
|
||||||
Resque.should_receive(:enqueue).with(Jobs::HttpPost, @url, @escaped_body, 1).once
|
Resque.should_receive(:enqueue).with(Job::HttpPost, @url, @escaped_body, 1).once
|
||||||
Jobs::HttpPost.perform(@url, @body, 2)
|
Job::HttpPost.perform(@url, @body, 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::NotifyLocalUsers do
|
describe Job::NotifyLocalUsers do
|
||||||
describe '#perfom' do
|
describe '#perfom' do
|
||||||
it 'should call Notification.notify on the object' do
|
it 'should call Notification.notify on the object' do
|
||||||
user = alice
|
user = alice
|
||||||
|
|
@ -12,7 +12,7 @@ describe Jobs::NotifyLocalUsers do
|
||||||
object = Factory :status_message
|
object = Factory :status_message
|
||||||
|
|
||||||
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))
|
||||||
Jobs::NotifyLocalUsers.perform(user.id, object.class.to_s, object.id, person.id)
|
Job::NotifyLocalUsers.perform(user.id, object.class.to_s, object.id, person.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::PostToService do
|
describe Job::PostToService do
|
||||||
it 'calls service#post with the given service' do
|
it 'calls service#post with the given service' do
|
||||||
user = alice
|
user = alice
|
||||||
aspect = user.aspects.create(:name => "yeah")
|
aspect = user.aspects.create(:name => "yeah")
|
||||||
|
|
@ -10,6 +10,6 @@ describe Jobs::PostToService do
|
||||||
url = "foobar"
|
url = "foobar"
|
||||||
m.should_receive(:post).with(anything, url)
|
m.should_receive(:post).with(anything, url)
|
||||||
Service.stub!(:find_by_id).and_return(m)
|
Service.stub!(:find_by_id).and_return(m)
|
||||||
Jobs::PostToService.perform("123", post.id.to_s, url)
|
Job::PostToService.perform("123", post.id.to_s, url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::PostToServices do
|
describe Job::PostToServices do
|
||||||
it 'calls post to services from the given user with given post' do
|
it 'calls post to services from the given user with given post' do
|
||||||
user = alice
|
user = alice
|
||||||
aspect = user.aspects.create(:name => "yeah")
|
aspect = user.aspects.create(:name => "yeah")
|
||||||
|
|
@ -10,6 +10,6 @@ describe Jobs::PostToServices do
|
||||||
url = "foobar"
|
url = "foobar"
|
||||||
m.should_receive(:post).with(anything, url)
|
m.should_receive(:post).with(anything, url)
|
||||||
user.stub!(:services).and_return([m])
|
user.stub!(:services).and_return([m])
|
||||||
Jobs::PostToServices.perform(user.id.to_s, post.id.to_s, url)
|
Job::PostToServices.perform(user.id.to_s, post.id.to_s, url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::PublishToHub do
|
describe Job::PublishToHub do
|
||||||
describe '.perform' do
|
describe '.perform' do
|
||||||
it 'calls pubsubhubbub' do
|
it 'calls pubsubhubbub' do
|
||||||
url = "http://publiczone.com/"
|
url = "http://publiczone.com/"
|
||||||
|
|
@ -12,7 +12,7 @@ describe Jobs::PublishToHub do
|
||||||
|
|
||||||
m.should_receive(:publish).with(url)
|
m.should_receive(:publish).with(url)
|
||||||
Pubsubhubbub.should_receive(:new).with(AppConfig[:pubsub_server]).and_return(m)
|
Pubsubhubbub.should_receive(:new).with(AppConfig[:pubsub_server]).and_return(m)
|
||||||
Jobs::PublishToHub.perform(url)
|
Job::PublishToHub.perform(url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::ReceiveLocal do
|
describe Job::ReceiveLocal do
|
||||||
before do
|
before do
|
||||||
@user1 = alice
|
@user1 = alice
|
||||||
@person1 = @user1.person
|
@person1 = @user1.person
|
||||||
|
|
@ -38,6 +38,6 @@ describe Jobs::ReceiveLocal do
|
||||||
m = mock()
|
m = mock()
|
||||||
m.should_receive(:receive_object)
|
m.should_receive(:receive_object)
|
||||||
Postzord::Receiver.should_receive(:new).and_return(m)
|
Postzord::Receiver.should_receive(:new).and_return(m)
|
||||||
Jobs::ReceiveLocal.perform(@user1.id, @person2.id, @status_type, @status.id)
|
Job::ReceiveLocal.perform(@user1.id, @person2.id, @status_type, @status.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::ReceiveSalmon do
|
describe Job::ReceiveSalmon do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@xml = '<xml></xml>'
|
@xml = '<xml></xml>'
|
||||||
|
|
@ -17,6 +17,6 @@ describe Jobs::ReceiveSalmon do
|
||||||
|
|
||||||
salmon_mock.should_receive(:perform)
|
salmon_mock.should_receive(:perform)
|
||||||
Postzord::Receiver.should_receive(:new).and_return(salmon_mock)
|
Postzord::Receiver.should_receive(:new).and_return(salmon_mock)
|
||||||
Jobs::ReceiveSalmon.perform(@user.id, @xml)
|
Job::ReceiveSalmon.perform(@user.id, @xml)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::Receive do
|
describe Job::Receive do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@person = Factory(:person)
|
@person = Factory(:person)
|
||||||
|
|
@ -18,6 +18,6 @@ describe Jobs::Receive do
|
||||||
zord_mock = mock()
|
zord_mock = mock()
|
||||||
zord_mock.should_receive(:parse_and_receive).with(@xml)
|
zord_mock.should_receive(:parse_and_receive).with(@xml)
|
||||||
Postzord::Receiver.should_receive(:new).with(@user, anything).and_return(zord_mock)
|
Postzord::Receiver.should_receive(:new).with(@user, anything).and_return(zord_mock)
|
||||||
Jobs::Receive.perform(@user.id, @xml, @person.id)
|
Job::Receive.perform(@user.id, @xml, @person.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Jobs::SocketWebfinger do
|
describe Job::SocketWebfinger do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@account = "tom@tom.joindiaspora.com"
|
@account = "tom@tom.joindiaspora.com"
|
||||||
end
|
end
|
||||||
it 'Makes a Webfinger object' do
|
it 'Makes a Webfinger object' do
|
||||||
Webfinger.should_receive(:new).with(@account)
|
Webfinger.should_receive(:new).with(@account)
|
||||||
Jobs::SocketWebfinger.perform(@user.id, @account)
|
Job::SocketWebfinger.perform(@user.id, @account)
|
||||||
end
|
end
|
||||||
it 'Queries the target account' do
|
it 'Queries the target account' do
|
||||||
finger = mock()
|
finger = mock()
|
||||||
Webfinger.stub(:new).and_return(finger)
|
Webfinger.stub(:new).and_return(finger)
|
||||||
|
|
||||||
finger.should_receive(:fetch).and_return(Factory.create(:person))
|
finger.should_receive(:fetch).and_return(Factory.create(:person))
|
||||||
Jobs::SocketWebfinger.perform(@user.id, @account)
|
Job::SocketWebfinger.perform(@user.id, @account)
|
||||||
end
|
end
|
||||||
it 'Sockets the resulting person on success' do
|
it 'Sockets the resulting person on success' do
|
||||||
finger = mock()
|
finger = mock()
|
||||||
|
|
@ -23,7 +23,7 @@ describe Jobs::SocketWebfinger do
|
||||||
finger.stub(:fetch).and_return(person)
|
finger.stub(:fetch).and_return(person)
|
||||||
|
|
||||||
person.should_receive(:socket_to_user).with(@user, {})
|
person.should_receive(:socket_to_user).with(@user, {})
|
||||||
Jobs::SocketWebfinger.perform(@user.id, @account)
|
Job::SocketWebfinger.perform(@user.id, @account)
|
||||||
end
|
end
|
||||||
it 'Passes opts through on success' do
|
it 'Passes opts through on success' do
|
||||||
finger = mock()
|
finger = mock()
|
||||||
|
|
@ -33,7 +33,7 @@ describe Jobs::SocketWebfinger do
|
||||||
|
|
||||||
opts = {:symbol => true}
|
opts = {:symbol => true}
|
||||||
person.should_receive(:socket_to_user).with(@user, opts)
|
person.should_receive(:socket_to_user).with(@user, opts)
|
||||||
Jobs::SocketWebfinger.perform(@user.id, @account, opts)
|
Job::SocketWebfinger.perform(@user.id, @account, opts)
|
||||||
end
|
end
|
||||||
it 'sockets failure message on failure' do
|
it 'sockets failure message on failure' do
|
||||||
finger = mock()
|
finger = mock()
|
||||||
|
|
@ -42,7 +42,7 @@ describe Jobs::SocketWebfinger do
|
||||||
|
|
||||||
opts = {:class => 'people', :status => 'fail', :query => @account, :response => I18n.t('people.webfinger.fail', :handle => @account )}.to_json
|
opts = {:class => 'people', :status => 'fail', :query => @account, :response => I18n.t('people.webfinger.fail', :handle => @account )}.to_json
|
||||||
Diaspora::WebSocket.should_receive(:queue_to_user).with(@user.id, opts)
|
Diaspora::WebSocket.should_receive(:queue_to_user).with(@user.id, opts)
|
||||||
Jobs::SocketWebfinger.perform(@user.id, @account)
|
Job::SocketWebfinger.perform(@user.id, @account)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ describe Diaspora::UserModules::Connecting do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'enqueues a mail job' do
|
it 'enqueues a mail job' do
|
||||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id)
|
Resque.should_receive(:enqueue).with(Job::MailRequestReceived, user.id, person.id)
|
||||||
zord = Postzord::Receiver.new(user, :object => @r, :person => person)
|
zord = Postzord::Receiver.new(user, :object => @r, :person => person)
|
||||||
zord.receive_object
|
zord.receive_object
|
||||||
end
|
end
|
||||||
|
|
@ -87,7 +87,7 @@ describe Diaspora::UserModules::Connecting do
|
||||||
Request.where(:sender_id => user2.person.id, :recipient_id => user.person.id).should be_empty
|
Request.where(:sender_id => user2.person.id, :recipient_id => user.person.id).should be_empty
|
||||||
end
|
end
|
||||||
it 'enqueues a mail job' do
|
it 'enqueues a mail job' do
|
||||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestAcceptance, user.id, user2.person.id).once
|
Resque.should_receive(:enqueue).with(Job::MailRequestAcceptance, user.id, user2.person.id).once
|
||||||
zord = Postzord::Receiver.new(user, :object => @acceptance, :person => user2.person)
|
zord = Postzord::Receiver.new(user, :object => @acceptance, :person => user2.person)
|
||||||
zord.receive_object
|
zord.receive_object
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -387,8 +387,8 @@ describe User do
|
||||||
user.save
|
user.save
|
||||||
user.reload
|
user.reload
|
||||||
|
|
||||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, 'contactrequestid').once
|
Resque.should_receive(:enqueue).with(Job::MailRequestReceived, user.id, 'contactrequestid').once
|
||||||
user.mail(Jobs::MailRequestReceived, user.id, 'contactrequestid')
|
user.mail(Job::MailRequestReceived, user.id, 'contactrequestid')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not enqueue a mail job' do
|
it 'does not enqueue a mail job' do
|
||||||
|
|
@ -397,7 +397,7 @@ describe User do
|
||||||
user.reload
|
user.reload
|
||||||
|
|
||||||
Resque.should_not_receive(:enqueue)
|
Resque.should_not_receive(:enqueue)
|
||||||
user.mail(Jobs::MailRequestReceived, user.id, 'contactrequestid')
|
user.mail(Job::MailRequestReceived, user.id, 'contactrequestid')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue