Class: NotificationWorkers::Partner::VouchersReport

Inherits:
ApplicationWorker show all
Includes:
MoneyRails::ActionViewExtension, RollbarSynTokenSetterWorker, Sidekiq::Status::Worker
Defined in:
app/workers/notification_workers/partner/vouchers_report.rb

Overview

typed: true frozen_string_literal: true

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Attribute Details

#attachmentObject

Returns the value of attribute attachment.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def attachment
  @attachment
end

#emailsObject

Returns the value of attribute emails.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def emails
  @emails
end

#package_type_codeObject

Returns the value of attribute package_type_code.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def package_type_code
  @package_type_code
end

#pdf_urlObject

Returns the value of attribute pdf_url.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def pdf_url
  @pdf_url
end

#restaurant_idObject

Returns the value of attribute restaurant_id.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def restaurant_id
  @restaurant_id
end

#selling_dateObject

Returns the value of attribute selling_date.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def selling_date
  @selling_date
end

#selling_end_dateObject

Returns the value of attribute selling_end_date.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def selling_end_date
  @selling_end_date
end

#selling_filter_typeObject

Returns the value of attribute selling_filter_type.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def selling_filter_type
  @selling_filter_type
end

#selling_start_dateObject

Returns the value of attribute selling_start_date.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def selling_start_date
  @selling_start_date
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def type
  @type
end

#valid_dateObject

Returns the value of attribute valid_date.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def valid_date
  @valid_date
end

#valid_date_fromObject

Returns the value of attribute valid_date_from.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def valid_date_from
  @valid_date_from
end

#valid_date_toObject

Returns the value of attribute valid_date_to.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def valid_date_to
  @valid_date_to
end

#valid_filter_typeObject

Returns the value of attribute valid_filter_type.



10
11
12
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 10

def valid_filter_type
  @valid_filter_type
end

Instance Method Details

#perform(args, attachment_id = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/workers/notification_workers/partner/vouchers_report.rb', line 16

def perform(args, attachment_id = nil)
  total 100
  store status: Attachment::ON_PROGRESS_STATUS
  store email_status: Attachment::PENDING_EMAIL_STATUS
  at 0

  self.attachment = Attachment.find_by(id: attachment_id) if attachment_id.present?
  attachment.update(status: :on_progress) if attachment.present?

  begin
    args.to_h.with_indifferent_access.each do |k, v|
      next if k.to_s == :use_long_process.to_s

      send("#{k}=".to_sym, v)
    end
    I18n.locale = :en
    vouchers_list = collect_vouchers_list

    if pdf?
      report = VouchersListReportPdf.new(vouchers_list)
      report.generate_pdf(vouchers_list, args)
      self.pdf_url = report.pdf_url
    else
      generate_vouchers_list_report_to_restaurant
      store_to_attachment
    end

    at(90)
    OwnerMailer.vouchers_list_report(email_body, email_subject, emails).deliver_later!
    store email_status: Attachment::SENT_EMAIL_STATUS

    mark_attachment_as_done
  rescue Aws::SES::Errors::Throttling => e
    store email_status: Attachment::FAILED_EMAIL_STATUS
    store message: "Email sending failed due to AWS SES throttling. Error: #{e.message}"
    raise e
  rescue StandardError => e
    store email_status: Attachment::FAILED_EMAIL_STATUS
    store message: "An error occurred: #{e.message}"
    store status: Attachment::FAILED_STATUS if attachment.blank? || attachment.download_link.blank?
    APMErrorHandler.report e
    raise e
  end
end