Class: CentralMail::SubmitSavedClaimJob
- Inherits:
-
Object
- Object
- CentralMail::SubmitSavedClaimJob
show all
- Includes:
- SentryLogging, Sidekiq::Job
- Defined in:
- app/sidekiq/central_mail/submit_saved_claim_job.rb
Defined Under Namespace
Classes: CentralMailResponseError
Constant Summary
collapse
- FOREIGN_POSTALCODE =
'00000'
- STATSD_KEY_PREFIX =
'worker.central_mail.submit_saved_claim_job'
- RETRY =
Sidekiq has built in exponential back-off functionality for retries A max retry attempt of 14 will result in a run time of ~25 hours
14
Instance Method Summary
collapse
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Instance Method Details
#create_request_body ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 75
def create_request_body
body = {
'metadata' => generate_metadata.to_json
}
body['document'] = to_faraday_upload(@pdf_path)
@attachment_paths.each_with_index do |file_path, i|
j = i + 1
body["attachment#{j}"] = to_faraday_upload(file_path)
end
body
end
|
rubocop:disable Metrics/MethodLength
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 119
def generate_metadata
form = @claim.parsed_form
form_pdf_metadata = get_hash_and_pages(@pdf_path)
number_attachments = @attachment_paths.size
veteran_full_name = form['veteranFullName']
address = form['claimantAddress'] || form['veteranAddress']
receive_date = @claim.created_at.in_time_zone('Central Time (US & Canada)')
metadata = {
'veteranFirstName' => remove_invalid_characters(veteran_full_name['first']),
'veteranLastName' => remove_invalid_characters(veteran_full_name['last']),
'fileNumber' => form['vaFileNumber'] || form['veteranSocialSecurityNumber'],
'receiveDt' => receive_date.strftime('%Y-%m-%d %H:%M:%S'),
'uuid' => @claim.guid,
'zipCode' => address['country'] == 'USA' ? address['postalCode'] : FOREIGN_POSTALCODE,
'source' => 'va.gov',
'hashV' => form_pdf_metadata[:hash],
'numberAttachments' => number_attachments,
'docType' => @claim.form_id,
'numberPages' => form_pdf_metadata[:pages]
}
@attachment_paths.each_with_index do |file_path, i|
j = i + 1
attachment_pdf_metadata = get_hash_and_pages(file_path)
metadata["ahash#{j}"] = attachment_pdf_metadata[:hash]
metadata["numberPages#{j}"] = attachment_pdf_metadata[:pages]
end
metadata
end
|
#get_hash_and_pages(file_path) ⇒ Object
111
112
113
114
115
116
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 111
def get_hash_and_pages(file_path)
{
hash: Digest::SHA256.file(file_path).hexdigest,
pages: PdfInfo::Metadata.read(file_path).pages
}
end
|
Performs an asynchronous job for submitting a saved claim to central mail service
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 37
def perform(saved_claim_id)
PensionBurial::TagSentry.tag_sentry
@saved_claim_id = saved_claim_id
log_message_to_sentry('Attempting CentralMail::SubmitSavedClaimJob', :info, generate_sentry_details)
response = send_claim_to_central_mail(saved_claim_id)
if response.success?
update_submission('success')
log_message_to_sentry('CentralMail::SubmitSavedClaimJob succeeded', :info, generate_sentry_details)
@claim.send_confirmation_email if @claim.respond_to?(:send_confirmation_email)
else
raise CentralMailResponseError, response.body
end
rescue => e
update_submission('failed')
log_message_to_sentry(
'CentralMail::SubmitSavedClaimJob failed, retrying...', :warn, generate_sentry_details(e)
)
raise
end
|
#process_record(record) ⇒ Object
100
101
102
103
104
105
106
107
108
109
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 100
def process_record(record)
pdf_path = record.to_pdf
stamped_path1 = CentralMail::DatestampPdf.new(pdf_path).run(text: 'VA.GOV', x: 5, y: 5)
CentralMail::DatestampPdf.new(stamped_path1).run(
text: 'FDC Reviewed - va.gov Submission',
x: 429,
y: 770,
text_only: true
)
end
|
#send_claim_to_central_mail(saved_claim_id) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 60
def send_claim_to_central_mail(saved_claim_id)
@claim = SavedClaim.find(saved_claim_id)
@pdf_path = process_record(@claim)
@attachment_paths = @claim.persistent_attachments.map do |record|
process_record(record)
end
response = CentralMail::Service.new.upload(create_request_body)
File.delete(@pdf_path)
@attachment_paths.each { |p| File.delete(p) }
response
end
|
#to_faraday_upload(file_path) ⇒ Object
93
94
95
96
97
98
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 93
def to_faraday_upload(file_path)
Faraday::UploadIO.new(
file_path,
Mime[:pdf].to_s
)
end
|
#update_submission(state) ⇒ Object
89
90
91
|
# File 'app/sidekiq/central_mail/submit_saved_claim_job.rb', line 89
def update_submission(state)
@claim.central_mail_submission.update!(state:) if @claim.respond_to?(:central_mail_submission)
end
|