1class FeedbackEmailJob < EmailJob
 
2  class SendingDisabledError < RuntimeError; end
 
3
 
4  self.mailer = FeedbackMailer
 
5  self.email = :send_feedback
 
6
 
7  rescue_from SendingDisabledError do
 
8    reschedule_job
 
 9  end
 
 
11  before_perform if: :feedback_sending_disabled? do
 
12    raise SendingDisabledError, "Feedback sending is currently disabled"
 
13  end
 
 
15  private
 
  • Complexity 1 » saikuro
17  def reschedule_job(time = 1.hour.from_now)
 
18    self.class.set(wait_until: time).perform_later(*arguments)
 
19  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
21  def feedback_sending_disabled?
 
22    Site.disable_feedback_sending?
 
23  end
 
24end