pull recipient & author up into MailNotificationJob

pull/3195/head
Jan Sandbrink 9 years ago
parent d43803ce85
commit 95c0d0a013
  1. 15
      app/workers/deliver_work_package_created_job.rb
  2. 15
      app/workers/deliver_work_package_updated_job.rb
  3. 27
      app/workers/mail_notification_job.rb

@ -27,13 +27,10 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
class DeliverWorkPackageCreatedJob
include MailNotificationJob
class DeliverWorkPackageCreatedJob < MailNotificationJob
def initialize(recipient_id, work_package_id, author_id)
@recipient_id = recipient_id
super(recipient_id, author_id)
@work_package_id = work_package_id
@author_id = author_id
end
private
@ -42,15 +39,7 @@ class DeliverWorkPackageCreatedJob
@notification_mail ||= UserMailer.work_package_added(recipient, work_package, author)
end
def recipient
@recipient ||= Principal.find(@recipient_id)
end
def work_package
@work_package ||= WorkPackage.find(@work_package_id)
end
def author
@author ||= Principal.find(@author_id)
end
end

@ -27,13 +27,10 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
class DeliverWorkPackageUpdatedJob
include MailNotificationJob
class DeliverWorkPackageUpdatedJob < MailNotificationJob
def initialize(recipient_id, journal_id, author_id)
@recipient_id = recipient_id
super(recipient_id, author_id)
@journal_id = journal_id
@author_id = author_id
end
private
@ -42,15 +39,7 @@ class DeliverWorkPackageUpdatedJob
@notification_mail ||= UserMailer.work_package_updated(recipient, journal, author)
end
def recipient
@recipient ||= Principal.find(@recipient_id)
end
def journal
@journal ||= Journal.find(@journal_id)
end
def author
@author ||= Principal.find(@author_id)
end
end

@ -29,13 +29,34 @@
##
# Requires including class to implement #notification_mail.
module MailNotificationJob
class MailNotificationJob
mattr_accessor :raise_exceptions
def initialize(recipient_id, author_id)
@recipient_id = recipient_id
@author_id = author_id
end
def perform
notify
end
def error(_job, e)
Rails.logger.error "notification failed (#{self.inspect}): #{e}"
end
protected
def recipient
@recipient ||= Principal.find(@recipient_id)
end
def author
@author ||= Principal.find(@author_id)
end
private
def notify
notification_mail.deliver
rescue ActiveRecord::RecordNotFound => e
@ -44,8 +65,4 @@ module MailNotificationJob
as required record was not found: #{e}".squish
raise e if raise_exceptions
end
def error(_job, e)
Rails.logger.error "notification failed (#{self.inspect}): #{e}"
end
end

Loading…
Cancel
Save