Class: DecisionReview::NodEmailLoaderJob

Inherits:
Object
  • Object
show all
Includes:
DecisionReviewV1::Appeals::LoggingUtils, Sidekiq::Job
Defined in:
app/sidekiq/decision_review/nod_email_loader_job.rb

Constant Summary collapse

LOG_PARAMS =
{
  key: :nod_email_loader_job,
  form_id: '10182',
  user_uuid: nil
}.freeze

Instance Method Summary collapse

Methods included from DecisionReviewV1::Appeals::LoggingUtils

#benchmark?, #benchmark_to_log_data_hash, #extract_uuid_from_central_mail_message, #log_formatted, #parse_form412_response_to_log_msg, #parse_lighthouse_response_to_log_msg, #run_and_benchmark_if_enabled

Instance Method Details

#get_csv(file_name, s3_config) ⇒ Object (private)

returns StringIO



38
39
40
41
42
43
44
# File 'app/sidekiq/decision_review/nod_email_loader_job.rb', line 38

def get_csv(file_name, s3_config)
  credentials = Aws::Credentials.new(s3_config[:aws_access_key_id], s3_config[:aws_secret_access_key])
  s3 = Aws::S3::Client.new(region: s3_config[:region], credentials:)
  s3.get_object(bucket: s3_config[:bucket], key: file_name).body
rescue => e
  raise "Error fetching #{file_name}: #{e}"
end

#perform(file_name, template_id, s3_config) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/sidekiq/decision_review/nod_email_loader_job.rb', line 18

def perform(file_name, template_id, s3_config)
  csv_file = get_csv(file_name, s3_config)

  line_num = 1

  csv_file.gets # skip CSV header
  csv_file.each_line do |line|
    email, full_name = line.split(',')
    DecisionReview::NodSendEmailJob.perform_async(email, template_id, { 'full_name' => full_name.strip }, line_num)
    line_num += 1
  end

  log_formatted(**LOG_PARAMS, is_success: true)
rescue => e
  log_formatted(**LOG_PARAMS, is_success: false, params: { exception_message: e.message })
end