Class: CentralMail::SubmitSavedClaimJob

Inherits:
Object
  • Object
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

Methods included from SentryLogging

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

Instance Method Details

#create_request_bodyObject



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' => .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

#generate_metadataObject

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 
  form = @claim.parsed_form
   = 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)')

   = {
    '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' => [:hash],
    'numberAttachments' => number_attachments,
    'docType' => @claim.form_id,
    'numberPages' => [:pages]
  }

  @attachment_paths.each_with_index do |file_path, i|
    j = i + 1
     = get_hash_and_pages(file_path)
    ["ahash#{j}"] = [:hash]
    ["numberPages#{j}"] = [:pages]
  end

  
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

#perform(saved_claim_id) ⇒ Object

Performs an asynchronous job for submitting a saved claim to central mail service

Parameters:

  • saved_claim_id (Integer)

    the claim id



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