Class: EVSS::RetrieveClaimsFromRemoteJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/evss/retrieve_claims_from_remote_job.rb

Instance Method Summary collapse

Instance Method Details

#claims_scopeObject (private)



43
44
45
# File 'app/sidekiq/evss/retrieve_claims_from_remote_job.rb', line 43

def claims_scope
  EVSSClaim.for_user(@user)
end

#create_or_update_claim(raw_claim) ⇒ Object (private)



32
33
34
35
36
37
38
39
40
41
# File 'app/sidekiq/evss/retrieve_claims_from_remote_job.rb', line 32

def create_or_update_claim(raw_claim)
  claim = claims_scope.where(evss_id: raw_claim['id']).first
  if claim.blank?
    claim = EVSSClaim.new(user_uuid: @user.uuid,
                          user_account: @user.,
                          evss_id: raw_claim['id'],
                          data: {})
  end
  claim.update(list_data: raw_claim)
end

#perform(user_uuid) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/sidekiq/evss/retrieve_claims_from_remote_job.rb', line 10

def perform(user_uuid)
  Sentry.set_tags(source: 'claims-status')
  @user = User.find user_uuid
  tracker = EVSSClaimsSyncStatusTracker.find_or_build(user_uuid)
  auth_headers = EVSS::AuthHeaders.new(@user).to_h
  @client = EVSS::ClaimsService.new(auth_headers)
  raw_claims = @client.all_claims.body
  EVSSClaimService::EVSS_CLAIM_KEYS.each_with_object([]) do |key, claim_accum|
    next unless raw_claims[key]

    claim_accum << raw_claims[key].map do |raw_claim|
      create_or_update_claim(raw_claim)
    end
  end
  tracker.set_collection_status('SUCCESS')
rescue
  tracker.set_collection_status('FAILED')
  raise
end