Class: CentralMail::SubmitForm4142Job
Defined Under Namespace
Classes: BenefitsIntake4142Error, CentralMailResponseError
Constant Summary
collapse
- INITIAL_FAILURE_EMAIL =
:form526_send_4142_failure_notification
- POLLING_FLIPPER_KEY =
:disability_526_form4142_polling_records
- POLLED_FAILURE_EMAIL =
:disability_526_form4142_polling_record_failure_email
- FORM4142_FORMSUBMISSION_TYPE =
"#{Form526Submission::FORM_526}_#{Form526Submission::FORM_4142}".freeze
- ZSF_DD_TAG_FUNCTION =
'526_form_4142_upload_failure_email_queuing'
- CENTRAL_MAIL_STATSD_KEY_PREFIX =
'worker.evss.submit_form4142'
- LIGHTHOUSE_STATSD_KEY_PREFIX =
'worker.lighthouse.submit_form4142'
Sidekiq::Form526JobStatusTracker::JobTracker::STATSD_KEY_PREFIX
Instance Attribute Summary collapse
-
#submission_id ⇒ Object
this is required to make instance variables available to logs via the wrap_with_logging method.
Instance Method Summary
collapse
wrap_with_logging
#submission
#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
#send_backup_submission_if_enabled
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Instance Attribute Details
#submission_id ⇒ Object
this is required to make instance variables available to logs via the wrap_with_logging method
25
26
27
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 25
def submission_id
@submission_id
end
|
Instance Method Details
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 248
def create_form_submission_attempt(form526_submission)
form_submission = form526_submission.saved_claim.form_submissions.find_by(form_type: FORM4142_FORMSUBMISSION_TYPE)
if form_submission.blank?
form_submission = FormSubmission.create(
form_type: FORM4142_FORMSUBMISSION_TYPE, form_data: '{}', user_account: form526_submission.user_account,
saved_claim: form526_submission.saved_claim
)
end
FormSubmissionAttempt.create(form_submission:, benefits_intake_uuid: lighthouse_service.uuid)
end
|
#create_service_error(key, source, response, _error = nil) ⇒ Object
234
235
236
237
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 234
def create_service_error(key, source, response, _error = nil)
response_values = response_values(key, source, response.status, response.body)
CentralMailResponseError.new(key, response_values, nil, nil)
end
|
#determine_zip ⇒ Object
212
213
214
215
216
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 212
def determine_zip
submission.form.dig('form526', 'form526', 'veteran', 'currentMailingAddress', 'zipFirstFive') ||
submission.form.dig('form526', 'form526', 'veteran', 'mailingAddress', 'zipFirstFive') ||
'00000'
end
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 194
def generate_metadata
vet_name = submission.full_name
filenumber = submission.['va_eauth_birlsfilenumber']
metadata = {
'veteranFirstName' => vet_name[:first],
'veteranLastName' => vet_name[:last],
'zipCode' => determine_zip,
'source' => 'Form526Submission va.gov',
'docType' => '4142',
'businessLine' => '',
'fileNumber' => filenumber
}
SimpleFormsApiSubmission::MetadataValidator
.validate(metadata, zip_code_is_us_based: usa_based?)
end
|
#handle_service_exception(response) ⇒ Object
Cannot move job straight to dead queue dynamically within an executing job raising error for all the exceptions as sidekiq will then move into dead queue after all retries are exhausted
229
230
231
232
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 229
def handle_service_exception(response)
error = create_service_error(nil, self.class, response)
raise error
end
|
#lighthouse_service ⇒ Object
161
162
163
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 161
def lighthouse_service
@lighthouse_service ||= BenefitsIntakeService::Service.new(with_upload_location: true)
end
|
#payload_hash(lighthouse_service_location) ⇒ Object
165
166
167
168
169
170
171
172
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 165
def payload_hash(lighthouse_service_location)
{
upload_url: lighthouse_service_location,
file: { file: @pdf_path, file_name: @pdf_path.split('/').last },
metadata: generate_metadata.to_json,
attachments: []
}
end
|
Performs an asynchronous job for submitting a Form 4142 to central mail service
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 115
def perform(submission_id)
@submission_id = submission_id
Sentry.set_tags(source: '526EZ-all-claims')
super(submission_id)
with_tracking('Form4142 Submission', submission.saved_claim_id, submission.id) do
@pdf_path = processor.pdf_path
response = upload_to_api
handle_service_exception(response) if response_can_be_logged(response)
end
rescue => e
retryable_error_handler(e)
raise e
ensure
File.delete(@pdf_path) if File.exist?(@pdf_path.to_s)
end
|
#response_can_be_logged(response) ⇒ Object
138
139
140
141
142
143
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 138
def response_can_be_logged(response)
response.present? &&
response.respond_to?(:status) &&
response.status.respond_to?(:between?) &&
response.status.between?(201, 600)
end
|
#response_values(key, source, status, detail) ⇒ Object
239
240
241
242
243
244
245
246
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 239
def response_values(key, source, status, detail)
{
status:,
detail:,
code: key,
source: source.to_s
}
end
|
#upload_to_api ⇒ Object
149
150
151
152
153
154
155
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 149
def upload_to_api
if Flipper.enabled?(:disability_compensation_form4142_supplemental)
upload_to_lighthouse
else
upload_to_central_mail
end
end
|
#upload_to_central_mail ⇒ Object
157
158
159
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 157
def upload_to_central_mail
CentralMail::Service.new.upload(processor.request_body)
end
|
#upload_to_lighthouse ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 174
def upload_to_lighthouse
log_info = { benefits_intake_uuid: lighthouse_service.uuid, submission_id: @submission_id }
Rails.logger.info(
'Successful Form4142 Upload Intake UUID acquired from Lighthouse',
log_info
)
payload = payload_hash(lighthouse_service.location)
response = lighthouse_service.upload_doc(**payload)
if Flipper.enabled?(POLLING_FLIPPER_KEY)
form526_submission = Form526Submission.find(@submission_id)
form_submission_attempt = create_form_submission_attempt(form526_submission)
log_info[:form_submission_id] = form_submission_attempt.form_submission.id
end
Rails.logger.info('Successful Form4142 Submission to Lighthouse', log_info)
response
end
|
#usa_based? ⇒ Boolean
218
219
220
221
222
223
224
|
# File 'app/sidekiq/central_mail/submit_form4142_job.rb', line 218
def usa_based?
country =
submission.form.dig('form526', 'form526', 'veteran', 'currentMailingAddress', 'country') ||
submission.form.dig('form526', 'form526', 'veteran', 'mailingAddress', 'country')
%w[USA US].include?(country&.upcase)
end
|