Class: BGS::FlashUpdater

Inherits:
Object
  • Object
show all
Extended by:
Logging::ThirdPartyTransaction::MethodWrapper
Includes:
SentryLogging, Sidekiq::Job
Defined in:
app/sidekiq/bgs/flash_updater.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'worker.bgs.flash_updater'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging::ThirdPartyTransaction::MethodWrapper

wrap_with_logging

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Instance Attribute Details

#submission_idObject

Returns the value of attribute submission_id.



12
13
14
# File 'app/sidekiq/bgs/flash_updater.rb', line 12

def submission_id
  @submission_id
end

Instance Method Details

#add_flashesObject (private)



84
85
86
87
88
89
90
91
92
# File 'app/sidekiq/bgs/flash_updater.rb', line 84

def add_flashes
  flashes.each do |flash_name|
    # NOTE: Assumption that duplicate flashes are ignored when submitted
    service.add_flash(file_number: ssn, flash_name:)
  rescue BGS::ShareError, BGS::PublicError => e
    Sentry.set_tags(source: '526EZ-all-claims', submission_id:)
    log_exception_to_sentry(e)
  end
end

#bgs_serviceObject (private)



122
123
124
125
126
127
128
# File 'app/sidekiq/bgs/flash_updater.rb', line 122

def bgs_service
  # BGS::Services is in the BGS bgs-ext gem, not to be confused with BGS::Service
  BGS::Services.new(
    external_uid: ssn,
    external_key: ssn
  )
end

#confirm_flash_additionObject (private)



94
95
96
97
98
99
100
101
102
103
104
# File 'app/sidekiq/bgs/flash_updater.rb', line 94

def confirm_flash_addition
  assigned_flashes = service.find_assigned_flashes(ssn)[:flashes]
  flashes.each do |flash_name|
    assigned_flash = assigned_flashes.find { |af| af[:flash_name].strip == flash_name }
    if assigned_flash.blank?
      Sentry.set_tags(source: '526EZ-all-claims', submission_id:)
      e = StandardError.new("Failed to assign '#{flash_name}' to Veteran")
      log_exception_to_sentry(e)
    end
  end
end

#flashesObject (private)



106
107
108
# File 'app/sidekiq/bgs/flash_updater.rb', line 106

def flashes
  @flashes ||= submission.form[Form526Submission::FLASHES]
end

#perform(submission_id) ⇒ Object



75
76
77
78
79
80
# File 'app/sidekiq/bgs/flash_updater.rb', line 75

def perform(submission_id)
  @submission_id = submission_id

  add_flashes
  confirm_flash_addition
end

#serviceObject (private)



118
119
120
# File 'app/sidekiq/bgs/flash_updater.rb', line 118

def service
  @service ||= bgs_service.claimant
end

#ssnObject (private)



114
115
116
# File 'app/sidekiq/bgs/flash_updater.rb', line 114

def ssn
  @ssn ||= submission.auth_headers['va_eauth_pnid']
end

#submissionObject (private)



110
111
112
# File 'app/sidekiq/bgs/flash_updater.rb', line 110

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