Class: Renalware::Letters::Mailshots::CreateMailshotLettersJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/renalware/letters/mailshots/create_mailshot_letters_job.rb

Overview

A background job to create letter records for a mailshot. More than 1000 letters in a mailshot could cause a timeout if executed while the user waits, which is why processing is done in the background.

Instance Method Summary collapse

Instance Method Details

#perform(mailshot) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'app/jobs/renalware/letters/mailshots/create_mailshot_letters_job.rb', line 13

def perform(mailshot)
  mailshot.update_column(:status, :processing)
  mailshot.create_letters
  mailshot.update_columns(status: :success, last_error: nil)
rescue StandardError => e
  mailshot.update_columns(
    last_error: "#{$ERROR_INFO}\nBacktrace:\n\t#{e.backtrace.join("\n\t")}",
    status: :failure
  )
  raise e
end