1class EmailJob < ApplicationJob
 
2  before_perform :set_appsignal_namespace
 
3
 
4  class_attribute :mailer, :email
 
5
 
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
 
  • Complexity 1 » saikuro
34  def perform(*args)
 
35    mailer.send(email, *args).deliver_now
 
36  end
 
 
38  private
 
  • Complexity 1 » saikuro
40  def log_exception(exception)
 
41    logger.info(log_message(exception))
 
42  end
 
  • Complexity 1 » saikuro
44  def log_message(exception)
 
45    "#{exception.class.name} while sending email for #{self.class.name}"
 
46  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
48  def set_appsignal_namespace
 
49    Appsignal.set_namespace("email")
 
50  end
 
51end