Class: DecisionReview::SavedClaimStatusUpdaterJob
- Inherits:
-
Object
- Object
- DecisionReview::SavedClaimStatusUpdaterJob
show all
- Includes:
- Sidekiq::Job
- Defined in:
- app/sidekiq/decision_review/saved_claim_status_updater_job.rb
Constant Summary
collapse
- RETENTION_PERIOD =
59.days
- FORM_SUCCESSFUL_STATUS =
'complete'
- UPLOAD_SUCCESSFUL_STATUS =
'vbms'
- ERROR_STATUS =
'error'
- NOT_FOUND =
'DR_404'
- ATTRIBUTES_TO_STORE =
%w[status detail createDate updateDate].freeze
- SECONDARY_FORM_ATTRIBUTES_TO_STORE =
%w[status detail updated_at].freeze
- FINAL_STATUSES =
%W[#{FORM_SUCCESSFUL_STATUS} #{UPLOAD_SUCCESSFUL_STATUS} #{ERROR_STATUS} #{NOT_FOUND}].freeze
Instance Method Summary
collapse
Instance Method Details
#check_attachments_status(record, uploads_metadata) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 206
def check_attachments_status(record, uploads_metadata)
result = true
old_uploads_metadata = (record.metadata)
uploads_metadata.each do |upload|
status = upload['status']
upload_id = upload['id']
result = false unless status == UPLOAD_SUCCESSFUL_STATUS
next if old_uploads_metadata.dig(upload_id, 'status') == status
if status == ERROR_STATUS
error_type = get_error_type(upload['detail'])
params = { guid: record.guid, lighthouse_upload_id: upload_id, detail: upload['detail'], error_type: }
Rails.logger.info("#{log_prefix} evidence status error", params)
end
StatsD.increment("#{statsd_prefix}_upload.status", tags: ["status:#{status}"])
end
result
end
|
#decision_review_service ⇒ Object
105
106
107
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 105
def decision_review_service
@service ||= DecisionReviewV1::Service.new
end
|
236
237
238
239
240
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 236
def (metadata)
return {} if metadata.nil?
JSON.parse(metadata).fetch('uploads', []).index_by { |upload| upload['id'] }
end
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 157
def get_and_update_secondary_form_statuses(record)
return true unless secondary_forms?
all_complete = true
return all_complete unless Flipper.enabled?(:decision_review_track_4142_submissions)
secondary_forms = record.appeal_submission&.secondary_appeal_forms
secondary_forms = secondary_forms&.filter { |form| form.delete_date.nil? } || []
secondary_forms.each do |form|
response = benefits_intake_service.get_status(uuid: form.guid).body
attributes = response.dig('data', 'attributes').slice(*SECONDARY_FORM_ATTRIBUTES_TO_STORE)
all_complete = false unless attributes['status'] == UPLOAD_SUCCESSFUL_STATUS
handle_secondary_form_status_metrics_and_logging(form, attributes['status'])
update_secondary_form_status(form, attributes)
end
all_complete
end
|
#get_error_type(detail) ⇒ Object
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 242
def get_error_type(detail)
case detail
when /.*Unidentified Mail: We could not associate part or all of this submission with a Vet*/i
'unidentified-mail'
when /.*ERR-EMMS-FAILED, Corrupted File detected.*/i
'corrupted-file'
when /.*ERR-EMMS-FAILED, Images failed to process.*/i
'image-processing-failure'
when /.*Errors: Batch Submitted with all blank Images.*/i
'blank-images'
when /.*Unsupported or Corrupted File type.*/i
'unsupported-file-type'
when /.ERR-EMMS-FAILED, EffectiveReceivedDate cannot be in the future.*/i
'effective-received-date-error'
else
'unknown'
end
end
|
#get_evidence_status(_guid) ⇒ Object
82
83
84
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 82
def get_evidence_status(_guid)
raise Common::Exceptions::NotImplemented
end
|
#get_evidence_uploads_statuses(record) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 127
def get_evidence_uploads_statuses(record)
return [] unless evidence?
result = []
attachment_ids = record.appeal_submission&.appeal_submission_uploads
&.pluck(:lighthouse_upload_id) || []
old_metadata = (record.metadata)
attachment_ids.each do |guid|
result << handle_evidence_status(guid, old_metadata.fetch(guid, {}))
end
result
end
|
#get_record_status(_guid) ⇒ Object
78
79
80
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 78
def get_record_status(_guid)
raise Common::Exceptions::NotImplemented
end
|
#get_status_and_attributes(record) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 109
def get_status_and_attributes(record)
metadata = JSON.parse(record.metadata || '{}')
old_status = metadata['status']
return [old_status, metadata.slice(*ATTRIBUTES_TO_STORE)] if FINAL_STATUSES.include? old_status
response = get_record_status(record.guid)
attributes = response.dig('data', 'attributes')
status = attributes['status']
[status, attributes]
rescue DecisionReviewV1::ServiceException => e
raise e unless e.key == NOT_FOUND
Rails.logger.error("#{log_prefix} error", { guid: record.guid, message: e.message })
[NOT_FOUND, { 'status' => NOT_FOUND }]
end
|
#handle_evidence_status(guid, metadata) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 142
def handle_evidence_status(guid, metadata)
status = metadata['status']
return metadata if FINAL_STATUSES.include? status
response = get_evidence_status(guid)
attributes = response.dig('data', 'attributes').slice(*ATTRIBUTES_TO_STORE)
attributes.merge('id' => guid)
rescue DecisionReviewV1::ServiceException => e
raise e unless e.key == NOT_FOUND
Rails.logger.error("#{log_prefix} get_evidence_status error", { guid:, message: e.message })
{ 'id' => guid, 'status' => NOT_FOUND }
end
|
177
178
179
180
181
182
183
184
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 177
def handle_form_status_metrics_and_logging(record, status)
return if JSON.parse(record.metadata || '{}')['status'] == status
Rails.logger.info("#{log_prefix} form status error", guid: record.guid) if status == ERROR_STATUS
StatsD.increment("#{statsd_prefix}.status", tags: ["status:#{status}"])
end
|
186
187
188
189
190
191
192
193
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 186
def handle_secondary_form_status_metrics_and_logging(form, status)
return if JSON.parse(form.status || '{}')['status'] == status
Rails.logger.info("#{log_prefix} secondary form status error", guid: form.guid) if status == ERROR_STATUS
StatsD.increment("#{statsd_prefix}_secondary_form.status", tags: ["status:#{status}"])
end
|
30
31
32
33
34
35
36
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/decision_review/saved_claim_status_updater_job.rb', line 30
def perform
return unless should_perform?
StatsD.increment("#{statsd_prefix}.processing_records", records_to_update.size)
records_to_update.each do |record|
status, attributes = get_status_and_attributes(record)
uploads_metadata = get_evidence_uploads_statuses(record)
secondary_forms_complete = get_and_update_secondary_form_statuses(record)
timestamp = DateTime.now
params = { metadata: attributes.merge(uploads: uploads_metadata).to_json, metadata_updated_at: timestamp }
if record_complete?(record, status, uploads_metadata, secondary_forms_complete)
params[:delete_date] = timestamp + RETENTION_PERIOD
StatsD.increment("#{statsd_prefix}.delete_date_update")
else
handle_form_status_metrics_and_logging(record, status)
end
record.update(params)
rescue => e
StatsD.increment("#{statsd_prefix}.error")
Rails.logger.error("#{log_prefix} error", { guid: record.guid, message: e.message })
end
nil
end
|
#record_complete?(record, status, uploads_metadata, secondary_forms_complete) ⇒ Boolean
231
232
233
234
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 231
def record_complete?(record, status, uploads_metadata, secondary_forms_complete)
check_attachments_status(record,
uploads_metadata) && secondary_forms_complete && status == FORM_SUCCESSFUL_STATUS
end
|
#records_to_update ⇒ Object
62
63
64
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 62
def records_to_update
raise Common::Exceptions::NotImplemented
end
|
90
91
92
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 90
def secondary_forms?
raise Common::Exceptions::NotImplemented
end
|
98
99
100
101
102
103
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 98
def should_perform?
enabled? && records_to_update.present?
rescue => e
StatsD.increment("#{statsd_prefix}.error")
Rails.logger.error("#{log_prefix} error", { message: e.message })
end
|
#statsd_prefix ⇒ Object
66
67
68
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 66
def statsd_prefix
raise Common::Exceptions::NotImplemented
end
|
195
196
197
198
199
200
201
202
203
204
|
# File 'app/sidekiq/decision_review/saved_claim_status_updater_job.rb', line 195
def update_secondary_form_status(form, attributes)
status = attributes['status']
if status == UPLOAD_SUCCESSFUL_STATUS
StatsD.increment("#{statsd_prefix}_secondary_form.delete_date_update")
delete_date = (Time.current + RETENTION_PERIOD)
else
delete_date = nil
end
form.update!(status: attributes.to_json, status_updated_at: Time.current, delete_date:)
end
|