1class EmailJob < ApplicationJob |
|
2 before_perform :set_appsignal_namespace |
|
4 class_attribute :mailer, :email |
|
6 PERMANENT_FAILURES = [ |
|
7 Net::SMTPFatalError, |
|
8 Net::SMTPSyntaxError |
|
9 ]
|
|
11 TEMPORARY_FAILURES = [ |
|
12 Net::SMTPAuthenticationError, |
|
13 Net::OpenTimeout, |
|
14 Net::SMTPServerBusy, |
|
15 Errno::ECONNRESET, |
|
16 Errno::ECONNREFUSED, |
|
17 Errno::ETIMEDOUT, |
|
18 Timeout::Error, |
|
19 EOFError, |
|
20 SocketError |
|
21 ]
|
|
23 queue_as :high_priority |
|
25 rescue_from *PERMANENT_FAILURES do |exception| |
|
26 log_exception(exception)
|
|
27 end |
|
29 rescue_from *TEMPORARY_FAILURES do |exception| |
|
30 log_exception(exception)
|
|
31 retry_job
|
|
32 end |
|
|
34 def perform(*args) |
35 mailer.send(email, *args).deliver_now
|
|
36 end |
|
38 private
|
|
|
40 def log_exception(exception) |
41 logger.info(log_message(exception))
|
|
42 end |
|
|
44 def log_message(exception) |
45 "#{exception.class.name} while sending email for #{self.class.name}" |
|
46 end |
|
|
48 def set_appsignal_namespace |
49 Appsignal.set_namespace("email") |
|
50 end |
|
51end |