Class: EducationForm::Create10203ApplicantDecisionLetters

Inherits:
Object
  • Object
show all
Includes:
SentryLogging, Sidekiq::Job
Defined in:
app/sidekiq/education_form/create10203_applicant_decision_letters.rb

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Instance Method Details

#inform_on_error(claim, error = nil) ⇒ Object (private)



45
46
47
48
49
50
# File 'app/sidekiq/education_form/create10203_applicant_decision_letters.rb', line 45

def inform_on_error(claim, error = nil)
  region = EducationFacility.facility_for(region: :eastern)
  StatsD.increment("worker.education_benefits_claim.applicant_denial_letter.#{region}.22-#{claim.form_type}")
  exception = FormattingError.new("Could not email denial letter for #{claim.confirmation_number}.\n\n#{error}")
  log_exception_to_sentry(exception)
end

#log_info(message) ⇒ Object (private)



52
53
54
# File 'app/sidekiq/education_form/create10203_applicant_decision_letters.rb', line 52

def log_info(message)
  logger.info(message)
end

#perform(records: EducationBenefitsClaim.includes(:saved_claim, :education_stem_automated_decision).where( saved_claims: { form_id: '22-10203' }, education_stem_automated_decisions: { automated_decision_state: EducationStemAutomatedDecision::DENIED, denial_email_sent_at: nil } )) ⇒ Object

Get all 10203 submissions that have a row in education_stem_automated_decisions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/sidekiq/education_form/create10203_applicant_decision_letters.rb', line 16

def perform(
  records: EducationBenefitsClaim.includes(:saved_claim, :education_stem_automated_decision).where(
    saved_claims: {
      form_id: '22-10203'
    },
    education_stem_automated_decisions: {
      automated_decision_state: EducationStemAutomatedDecision::DENIED,
      denial_email_sent_at: nil
    }
  )
)
  if records.count.zero?
    log_info('No records to process.')
    return true
  else
    log_info("Processing #{records.count} denied application(s)")
  end

  records.each do |record|
    StemApplicantDenialMailer.build(record, nil).deliver_now
    record.education_stem_automated_decision.update(denial_email_sent_at: Time.zone.now)
  rescue => e
    inform_on_error(record, e)
  end
  true
end