Class: Lighthouse::PollForm526Pdf

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern, Logging::ThirdPartyTransaction::MethodWrapper, SentryLogging
Includes:
Sidekiq::Form526JobStatusTracker::JobTracker, Sidekiq::Job
Defined in:
app/sidekiq/lighthouse/poll_form526_pdf.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'worker.lighthouse.poll_form526_pdf'

Instance Attribute Summary collapse

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

Methods included from Logging::ThirdPartyTransaction::MethodWrapper

wrap_with_logging

Methods included from Sidekiq::Form526JobStatusTracker::JobTracker

#error_message, #job_success, #job_try, #klass, #log_error, #log_info, #metrics, #non_retryable_error_handler, #retryable_error_handler, #update_background_job_errors, #upsert_job_status, #with_tracking

Methods included from Sidekiq::Form526JobStatusTracker::BackupSubmission

#send_backup_submission_if_enabled

Instance Attribute Details

#submission_idObject

Returns the value of attribute submission_id.



50
51
52
# File 'app/sidekiq/lighthouse/poll_form526_pdf.rb', line 50

def submission_id
  @submission_id
end

Instance Method Details

#get_form526_pdf(submission) ⇒ Object (private)



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/sidekiq/lighthouse/poll_form526_pdf.rb', line 126

def get_form526_pdf(submission)
  icn = submission..icn
  service = BenefitsClaims::Service.new(icn)
  raw_response = service.get_claim(submission.)
  raw_response_body = if raw_response.is_a? String
                        JSON.parse(raw_response)
                      else
                        raw_response
                      end

  supporting_documents = raw_response_body.dig('data', 'attributes', 'supportingDocuments')
  supporting_documents.find do |d|
    d['documentTypeLabel'] == 'VA 21-526 Veterans Application for Compensation or Pension'
  end
end

#perform(submission_id) ⇒ Object

Checks claims status for supporting documents for a submission and exits out when found. If the timeout period is exceeded (48 hours), then the ‘pdf_not_found’ status is written to Form526JobStatus

Parameters:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/sidekiq/lighthouse/poll_form526_pdf.rb', line 90

def perform(submission_id)
  @submission_id = submission_id

  Sentry.set_tags(source: '526EZ-all-claims')

  with_tracking('Form526 Submission', submission.saved_claim_id, submission.id, submission.bdd?) do
    form526_pdf = get_form526_pdf(submission)
    if form526_pdf.present?
      Rails.logger.info('Poll for form 526 PDF: PDF found')
      send_confirmation_email(submission) if Flipper.enabled?(:disability_526_call_received_email_from_polling)
      return
    else
      # Check the submission.created_at date, if it's more than 2 days old
      # update the job status to pdf_not_found immediately and exit the job
      unless submission.created_at.between?(DateTime.now - 2.days, DateTime.now)
        form_job_status = submission.form526_job_statuses.find_by(job_class: 'PollForm526Pdf')
        message = 'Poll for form 526 PDF: Submission creation date is over 2 days old. Exiting...'
        PollForm526PdfStatus.update_job_status(
          form_job_status:,
          message:,
          error_class: 'PollForm526PdfError',
          error_message: message
        )
        return
      end
      raise Lighthouse::PollForm526PdfError, 'Poll for form 526 PDF: Keep on retrying!'
    end
  end
end

#send_confirmation_email(submission) ⇒ Object (private)



142
143
144
145
146
147
148
149
150
# File 'app/sidekiq/lighthouse/poll_form526_pdf.rb', line 142

def send_confirmation_email(submission)
  user_uuid = submission.user_uuid
  Rails.logger.info("Form526ConfirmationEmailJob called for user #{user_uuid},
                                                    submission: #{submission_id} from poll_form526_pdf")

  first_name = submission.get_first_name
  params = submission.personalization_parameters(first_name)
  Form526ConfirmationEmailJob.perform_async(params)
end

#submissionObject (private)



122
123
124
# File 'app/sidekiq/lighthouse/poll_form526_pdf.rb', line 122

def submission
  @submission ||= Form526Submission.find(@submission_id)
end