Commit 97f80272 authored by danielgrippi's avatar danielgrippi

DG MS; changed Job:: to Jobs::; require all mail jobs from Job base class

parent ec011f08
......@@ -56,7 +56,7 @@ class InvitationsController < Devise::InvitationsController
def resend
invitation = current_user.invitations_from_me.where(:id => params[:id]).first
if invitation
Resque.enqueue(Job::ResendInvitation, invitation.id)
Resque.enqueue(Jobs::ResendInvitation, invitation.id)
flash[:notice] = I18n.t('invitations.create.sent') + invitation.recipient.email
end
redirect_to :back
......
......@@ -171,7 +171,7 @@ class PeopleController < ApplicationController
private
def webfinger(account, opts = {})
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts)
end
def remote_profile_with_no_user_session?
......
......@@ -50,7 +50,7 @@ class PublicsController < ApplicationController
end
def receive_public
Resque.enqueue(Job::ReceivePublicSalmon, params[:xml])
Resque.enqueue(Jobs::ReceivePublicSalmon, params[:xml])
render :nothing => true, :status => :ok
end
......@@ -64,7 +64,7 @@ class PublicsController < ApplicationController
end
@user = person.owner
Resque.enqueue(Job::ReceiveSalmon, @user.id, CGI::unescape(params[:xml]))
Resque.enqueue(Jobs::ReceiveSalmon, @user.id, CGI::unescape(params[:xml]))
render :nothing => true, :status => 202
end
......
......@@ -10,7 +10,7 @@ class SessionsController < Devise::SessionsController
def enqueue_update
if current_user
current_user.services.each do |s|
Resque.enqueue(Job::UpdateServiceUsers, s.id) if s.respond_to? :save_friends
Resque.enqueue(Jobs::UpdateServiceUsers, s.id) if s.respond_to? :save_friends
end
end
end
......
......@@ -68,7 +68,7 @@ class UsersController < ApplicationController
end
def destroy
Resque.enqueue(Job::DeleteAccount, current_user.id)
Resque.enqueue(Jobs::DeleteAccount, current_user.id)
current_user.lock_access!
sign_out current_user
flash[:notice] = I18n.t 'users.destroy'
......
......@@ -135,7 +135,7 @@ class Invitation < ActiveRecord::Base
def queue_send!
unless self.recipient.present?
Resque.enqueue(Job::Mail::InviteUserByEmail, self.id)
Resque.enqueue(Jobs::Mail::InviteUserByEmail, self.id)
end
end
......
module Job
class Base
extend ResqueJobLogging
end
end
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Jobs
class Base
Dir["#{Rails.root}/app/models/jobs/mail/*.rb"].each {|file| require file }
extend ResqueJobLogging
end
end
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
class DeleteAccount < Base
@queue = :delete_account
def self.perform(user_id)
......
......@@ -5,7 +5,7 @@
require 'uri'
require File.join(Rails.root, 'lib/hydra_wrapper')
module Job
module Jobs
class HttpMulti < Base
@queue = :http
......@@ -26,7 +26,7 @@ module Job
unless hydra.failed_people.empty?
if retry_count < MAX_RETRIES
Resque.enqueue(Job::HttpMulti, user_id, encoded_object_xml, hydra.failed_people, dispatcher_class_as_string, retry_count + 1 )
Resque.enqueue(Jobs::HttpMulti, user_id, encoded_object_xml, hydra.failed_people, dispatcher_class_as_string, retry_count + 1 )
else
Rails.logger.info("event=http_multi_abandon sender_id=#{user_id} failed_recipient_ids='[#{person_ids.join(', ')}] '")
end
......
module Job
module Jobs
module Mail
class AlsoCommented < Base
@queue = :mail
......
module Job
module Jobs
module Mail
class CommentOnPost < Base
@queue = :mail
......
module Job
module Jobs
module Mail
class ConfirmEmail < Base
@queue = :mail
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
module Mail
class InviteUserByEmail < Base
@queue = :mail
......
module Job
module Jobs
module Mail
class Liked < Base
@queue = :mail
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
module Mail
class Mentioned < Base
@queue = :mail
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
module Mail
class PrivateMessage < Base
@queue = :mail
......
module Job
module Jobs
module Mail
class Reshared < Base
@queue = :mail
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
module Mail
class StartedSharing < Base
@queue = :mail
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Job
module Jobs
class NotifyLocalUsers < Base
@queue = :receive_local
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
module Job
module Jobs
class PostToService < Base
@queue = :http_service
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
class ProcessPhoto < Base
@queue = :photos
def self.perform(photo_id)
......
......@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module Job
module Jobs
class PublishToHub < Base
@queue = :http_service
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
class Receive < Base
@queue = :receive
......
......@@ -5,7 +5,7 @@
require File.join(Rails.root, 'lib/postzord/receiver/private')
require File.join(Rails.root, 'lib/postzord/receiver/local_post_batch')
module Job
module Jobs
class ReceiveLocalBatch < Base
@queue = :receive
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver/private')
module Job
module Jobs
class ReceivePublicSalmon < Base
@queue = :receive
......
......@@ -4,7 +4,7 @@
require File.join(Rails.root, 'lib/postzord/receiver/private')
module Job
module Jobs
class ReceiveSalmon < Base
@queue = :receive_salmon
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
class ResendInvitation < Base
@queue = :mail
def self.perform(invitation_id)
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
class SocketWebfinger < Base
@queue = :socket_webfinger
......
......@@ -3,7 +3,7 @@
# the COPYRIGHT file.
module Job
module Jobs
class UpdateServiceUsers < Base
@queue = :http_service
def self.perform(service_id)
......
class Notifications::AlsoCommented < Notification
def mail_job
Job::Mail::AlsoCommented
Jobs::Mail::AlsoCommented
end
def popup_translation_key
......
class Notifications::CommentOnPost < Notification
def mail_job
Job::Mail::CommentOnPost
Jobs::Mail::CommentOnPost
end
def popup_translation_key
......
class Notifications::Liked < Notification
def mail_job
Job::Mail::Liked
Jobs::Mail::Liked
end
def popup_translation_key
......
class Notifications::Mentioned < Notification
def mail_job
Job::Mail::Mentioned
Jobs::Mail::Mentioned
end
def popup_translation_key
......
class Notifications::PrivateMessage < Notification
def mail_job
Job::Mail::PrivateMessage
Jobs::Mail::PrivateMessage
end
def popup_translation_key
'notifications.private_message'
......
class Notifications::RequestAccepted < Notification
def mail_job
Job::Mail::RequestAcceptance
Jobs::Mail::RequestAcceptance
end
def popup_translation_key
'notifications.request_accepted'
......
class Notifications::Reshared < Notification
def mail_job
Job::Mail::Reshared
#Job::Mail::Liked
Jobs::Mail::Reshared
#Jobs::Mail::Liked
end
def popup_translation_key
......
class Notifications::StartedSharing < Notification
def mail_job
Job::Mail::StartedSharing
Jobs::Mail::StartedSharing
end
def popup_translation_key
......
......@@ -94,7 +94,7 @@ class Photo < Post
end
def queue_processing_job
Resque.enqueue(Job::ProcessPhoto, self.id)
Resque.enqueue(Jobs::ProcessPhoto, self.id)
end
def process
......
......@@ -266,7 +266,7 @@ class User < ActiveRecord::Base
######### Mailer #######################
def mail(job, *args)
pref = job.to_s.gsub('Job::Mail::', '').underscore
pref = job.to_s.gsub('Jobs::Mail::', '').underscore
if(self.disable_mail == false && !self.user_preferences.exists?(:email_type => pref))
Resque.enqueue(job, *args)
end
......@@ -274,7 +274,7 @@ class User < ActiveRecord::Base
def mail_confirm_email
return false if unconfirmed_email.blank?
Resque.enqueue(Job::Mail::ConfirmEmail, id)
Resque.enqueue(Jobs::Mail::ConfirmEmail, id)
true
end
......
......@@ -96,7 +96,7 @@ class Postzord::Dispatcher
else
people.each do |person|
Rails.logger.info("event=push route=local sender=#{@sender.person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}")
Resque.enqueue(Job::Receive, person.owner_id, @xml, @sender.person.id)
Resque.enqueue(Jobs::Receive, person.owner_id, @xml, @sender.person.id)
end
end
end
......@@ -104,13 +104,13 @@ class Postzord::Dispatcher
# @param people [Array<Person>] Recipients of the post
def batch_deliver_to_local(people)
ids = people.map{ |p| p.owner_id }
Resque.enqueue(Job::ReceiveLocalBatch, @object.class.to_s, @object.id, ids)
Resque.enqueue(Jobs::ReceiveLocalBatch, @object.class.to_s, @object.id, ids)
Rails.logger.info("event=push route=local sender=#{@sender.person.diaspora_handle} recipients=#{ids.join(',')} payload_type=#{@object.class}")
end
def deliver_to_hub
Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}")
Resque.enqueue(Job::PublishToHub, @sender.public_url)
Resque.enqueue(Jobs::PublishToHub, @sender.public_url)
end
# @param url [String]
......@@ -121,7 +121,7 @@ class Postzord::Dispatcher
end
if @object.instance_of?(StatusMessage)
services.each do |service|
Resque.enqueue(Job::PostToService, service.id, @object.id, url)
Resque.enqueue(Jobs::PostToService, service.id, @object.id, url)
end
end
end
......@@ -137,7 +137,7 @@ class Postzord::Dispatcher
# @param services [Array<User>]
def notify_users(users)
return unless users.present? && @object.respond_to?(:persisted?)
Resque.enqueue(Job::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id)
Resque.enqueue(Jobs::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id)
end
# @param services [Array<User>]
......@@ -152,7 +152,7 @@ class Postzord::Dispatcher
# @param remote_people [Array<Person>] Recipients of the post on other pods
# @return [void]
def queue_remote_delivery_job(remote_people)
Resque.enqueue(Job::HttpMulti, @sender.id, Base64.encode64(@object.to_diaspora_xml), remote_people.map{|p| p.id}, self.class.to_s)
Resque.enqueue(Jobs::HttpMulti, @sender.id, Base64.encode64(@object.to_diaspora_xml), remote_people.map{|p| p.id}, self.class.to_s)
end
end
......@@ -25,7 +25,7 @@ module Postzord
if @object.respond_to?(:relayable?)
receive_relayable
else
Resque.enqueue(Job::ReceiveLocalBatch, @object.id, self.recipient_user_ids)
Resque.enqueue(Jobs::ReceiveLocalBatch, @object.id, self.recipient_user_ids)
end
end
......
......@@ -387,7 +387,7 @@ describe PeopleController do
describe '#webfinger' do
it 'enqueues a webfinger job' do
Resque.should_receive(:enqueue).with(Job::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once
Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, @user.id, @user.diaspora_handle, anything).once
get :retrieve_remote, :diaspora_handle => @user.diaspora_handle
end
end
......
......@@ -33,7 +33,7 @@ describe PublicsController do
it 'enqueues a ReceivePublicSalmon job' do
xml = "stuff"
Resque.should_receive(:enqueue).with(Job::ReceivePublicSalmon, xml)
Resque.should_receive(:enqueue).with(Jobs::ReceivePublicSalmon, xml)
post :receive_public, :xml => xml
end
end
......@@ -47,7 +47,7 @@ describe PublicsController do
end
it 'enqueues a receive job' do
Resque.should_receive(:enqueue).with(Job::ReceiveSalmon, @user.id, xml).once
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, xml).once
post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
end
......@@ -60,7 +60,7 @@ describe PublicsController do
salmon_factory = Salmon::EncryptedSlap.create_by_user_and_activity(@user, xml2)
enc_xml = salmon_factory.xml_for(user2.person)
Resque.should_receive(:enqueue).with(Job::ReceiveSalmon, @user.id, enc_xml).once
Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, @user.id, enc_xml).once
post :receive, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
end
......
......@@ -40,7 +40,7 @@ describe SessionsController do
it 'queues up an update job' do
service = Services::Facebook.new(:access_token => "yeah")
@user.services << service
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, service.id)
Resque.should_receive(:enqueue).with(Jobs::UpdateServiceUsers, service.id)
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
end
......
......@@ -124,7 +124,7 @@ describe UsersController do
end
it 'sends out activation email on success' do
Resque.should_receive(:enqueue).with(Job::Mail::ConfirmEmail, @user.id).once
Resque.should_receive(:enqueue).with(Jobs::Mail::ConfirmEmail, @user.id).once
put(:update, :id => @user.id, :user => { :email => "my@newemail.com"})
end
end
......@@ -169,7 +169,7 @@ describe UsersController do
describe '#destroy' do
it 'enqueues a delete job' do
Resque.should_receive(:enqueue).with(Job::DeleteAccount, alice.id)
Resque.should_receive(:enqueue).with(Jobs::DeleteAccount, alice.id)
delete :destroy
end
......
......@@ -227,7 +227,7 @@ describe Postzord::Dispatcher do
end
it 'should queue an HttpPost job for each remote person' do
Resque.should_receive(:enqueue).with(Job::HttpMulti, alice.id, anything, @remote_people.map{|p| p.id}, anything).once
Resque.should_receive(:enqueue).with(Jobs::HttpMulti, alice.id, anything, @remote_people.map{|p| p.id}, anything).once
@mailman.send(:deliver_to_remote, @remote_people)
end
end
......@@ -240,7 +240,7 @@ describe Postzord::Dispatcher do
it 'queues a batch receive' do
local_people = []
local_people << alice.person
Resque.should_receive(:enqueue).with(Job::ReceiveLocalBatch, @sm.class.to_s, @sm.id, [alice.id]).once
Resque.should_receive(:enqueue).with(Jobs::ReceiveLocalBatch, @sm.class.to_s, @sm.id, [alice.id]).once
@mailman.send(:deliver_to_local, local_people)
end
......@@ -264,8 +264,8 @@ describe Postzord::Dispatcher do
end
it 'queues a job to notify the hub' do
Resque.stub!(:enqueue).with(Job::PostToService, anything, anything, anything)
Resque.should_receive(:enqueue).with(Job::PublishToHub, alice.public_url)
Resque.stub!(:enqueue).with(Jobs::PostToService, anything, anything, anything)
Resque.should_receive(:enqueue).with(Jobs::PublishToHub, alice.public_url)
@zord.send(:deliver_to_services, nil, [])
end
......@@ -284,17 +284,17 @@ describe Postzord::Dispatcher do
alice.services << @s2
mailman = Postzord::Dispatcher.build(alice, Factory(:status_message))
Resque.stub!(:enqueue).with(Job::PublishToHub, anything)
Resque.stub!(:enqueue).with(Job::HttpMulti, anything, anything, anything)
Resque.should_receive(:enqueue).with(Job::PostToService, @s1.id, anything, anything)
Resque.stub!(:enqueue).with(Jobs::PublishToHub, anything)
Resque.stub!(:enqueue).with(Jobs::HttpMulti, anything, anything, anything)
Resque.should_receive(:enqueue).with(Jobs::PostToService, @s1.id, anything, anything)
mailman.post(:url => "http://joindiaspora.com/p/123", :services => [@s1])
end
it 'does not push to services if none are specified' do
mailman = Postzord::Dispatcher.build(alice, Factory(:status_message))
Resque.stub!(:enqueue).with(Job::PublishToHub, anything)
Resque.should_not_receive(:enqueue).with(Job::PostToService, anything, anything, anything)
Resque.stub!(:enqueue).with(Jobs::PublishToHub, anything)
Resque.should_not_receive(:enqueue).with(Jobs::PostToService, anything, anything, anything)
mailman.post(:url => "http://joindiaspora.com/p/123")
end
end
......@@ -313,7 +313,7 @@ describe Postzord::Dispatcher do
describe '#notify_users' do
it 'enqueues a NotifyLocalUsers job' do
Resque.should_receive(:enqueue).with(Job::NotifyLocalUsers, [bob.id], @zord.object.class.to_s, @zord.object.id, @zord.object.author.id)
Resque.should_receive(:enqueue).with(Jobs::NotifyLocalUsers, [bob.id], @zord.object.class.to_s, @zord.object.id, @zord.object.author.id)
@zord.send(:notify_users, [bob])
end
end
......
......@@ -55,8 +55,8 @@ describe Postzord::Receiver::Public do
@receiver.perform!
end
it 'enqueues a Job::ReceiveLocalBatch' do
Resque.should_receive(:enqueue).with(Job::ReceiveLocalBatch, anything, anything)
it 'enqueues a Jobs::ReceiveLocalBatch' do
Resque.should_receive(:enqueue).with(Jobs::ReceiveLocalBatch, anything, anything)
@receiver.perform!
end
end
......
......@@ -4,18 +4,18 @@
require 'spec_helper'
describe Job::DeleteAccount do
describe Jobs::DeleteAccount do
describe '#perform' do
it 'calls remove_all_traces' do
stub_find_for(bob)
bob.should_receive(:remove_all_traces)
Job::DeleteAccount.perform(bob.id)
Jobs::DeleteAccount.perform(bob.id)
end
it 'calls destroy' do
stub_find_for(bob)
bob.should_receive(:destroy)
Job::DeleteAccount.perform(bob.id)
Jobs::DeleteAccount.perform(bob.id)
end
def stub_find_for model
model.class.stub!(:find) do |id, conditions|
......