Class: Form526ParanoidSuccessPollingJob
- Inherits:
-
Object
- Object
- Form526ParanoidSuccessPollingJob
- Includes:
- Sidekiq::Job
- Defined in:
- app/sidekiq/form526_paranoid_success_polling_job.rb
Constant Summary collapse
- MAX_BATCH_SIZE =
1000
Instance Attribute Summary collapse
-
#change_totals ⇒ Object
readonly
Returns the value of attribute change_totals.
-
#max_batch_size ⇒ Object
readonly
Returns the value of attribute max_batch_size.
-
#total_checked ⇒ Object
readonly
Returns the value of attribute total_checked.
Instance Method Summary collapse
- #api_to_poll ⇒ Object private
- #count_change(status) ⇒ Object private
- #handle_response(response) ⇒ Object private
- #handle_submission(form_submission, status, id) ⇒ Object private
-
#initialize(max_batch_size: MAX_BATCH_SIZE) ⇒ Form526ParanoidSuccessPollingJob
constructor
A new instance of Form526ParanoidSuccessPollingJob.
- #log_result(change, submission_id) ⇒ Object private
- #perform ⇒ Object
- #submissions ⇒ Object private
Constructor Details
#initialize(max_batch_size: MAX_BATCH_SIZE) ⇒ Form526ParanoidSuccessPollingJob
Returns a new instance of Form526ParanoidSuccessPollingJob.
12 13 14 15 16 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 12 def initialize(max_batch_size: MAX_BATCH_SIZE) @max_batch_size = max_batch_size @total_checked = 0 @change_totals = {} end |
Instance Attribute Details
#change_totals ⇒ Object (readonly)
Returns the value of attribute change_totals.
10 11 12 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 10 def change_totals @change_totals end |
#max_batch_size ⇒ Object (readonly)
Returns the value of attribute max_batch_size.
10 11 12 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 10 def max_batch_size @max_batch_size end |
#total_checked ⇒ Object (readonly)
Returns the value of attribute total_checked.
10 11 12 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 10 def total_checked @total_checked end |
Instance Method Details
#api_to_poll ⇒ Object (private)
34 35 36 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 34 def api_to_poll @api_to_poll ||= BenefitsIntakeService::Service.new end |
#count_change(status) ⇒ Object (private)
70 71 72 73 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 70 def count_change(status) change_totals[status] ||= 0 change_totals[status] += 1 end |
#handle_response(response) ⇒ Object (private)
42 43 44 45 46 47 48 49 50 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 42 def handle_response(response) response.body['data']&.each do |submission| status = submission.dig('attributes', 'status') id = submission['id'] form_submission = Form526Submission.find_by(backup_submitted_claim_id: id) handle_submission(form_submission, status, id) @total_checked += 1 end end |
#handle_submission(form_submission, status, id) ⇒ Object (private)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 52 def handle_submission(form_submission, status, id) if %w[error expired].include?(status) form_submission.rejected! log_result('failed', id) elsif status == 'vbms' form_submission.accepted! log_result('marked as true success', id) elsif status == 'processing' form_submission.update!(backup_submitted_claim_status: nil) log_result('reverted to processing', id) elsif status != 'success' Rails.logger.error('Paranoid Success transitioned to unknown status', status:, submission_id: id) form_submission.rejected! end count_change(status) unless status == 'success' end |
#log_result(change, submission_id) ⇒ Object (private)
75 76 77 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 75 def log_result(change, submission_id) Rails.logger.info('Paranoid Success submission changed', submission_id:, change:) end |
#perform ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 18 def perform Rails.logger.info('Beginning Form 526 paranoid_success polling') submissions.in_batches(of: max_batch_size) do |batch| batch_ids = batch.pluck(:backup_submitted_claim_id).flatten response = api_to_poll.get_bulk_status_of_uploads(batch_ids) handle_response(response) end Rails.logger.info('Form 526 paranoid_success polling complete', total_checked:, change_totals:) rescue => e Rails.logger.error('Error processing 526 paranoid_success batch', class: self.class.name, message: e.) end |
#submissions ⇒ Object (private)
38 39 40 |
# File 'app/sidekiq/form526_paranoid_success_polling_job.rb', line 38 def submissions @submissions ||= Form526Submission.paranoid_success_type end |