Class: NotificationWorkers::Partner::PerformanceReviewReport

Inherits:
ApplicationWorker show all
Includes:
MoneyRails::ActionViewExtension, RollbarSynTokenSetterWorker, Sidekiq::Status::Worker
Defined in:
app/workers/notification_workers/partner/performance_review_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

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#date_filter_typeObject

Returns the value of attribute date_filter_type.



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

def date_filter_type
  @date_filter_type
end

#emailsObject

Returns the value of attribute emails.



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

def emails
  @emails
end

#end_dateObject

Returns the value of attribute end_date.



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

def end_date
  @end_date
end

#ex_urlObject

Returns the value of attribute ex_url.



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

def ex_url
  @ex_url
end

#pdf_urlObject

Returns the value of attribute pdf_url.



10
11
12
# File 'app/workers/notification_workers/partner/performance_review_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/performance_review_report.rb', line 10

def restaurant_id
  @restaurant_id
end

#start_dateObject

Returns the value of attribute start_date.



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

def start_date
  @start_date
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#perform(args, attachment_id = nil) ⇒ Object



14
15
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
# File 'app/workers/notification_workers/partner/performance_review_report.rb', line 14

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?
  return if attachment.blank?

  attachment.update(status: :on_progress)

  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
    if pdf?
      report = PerformanceReviewReportPdf.new(args)
      report.generate_pdf(args)
      self.pdf_url = report.pdf_url
    else
      generate_excel
      store_to_attachment
    end

    at(90)
    OwnerMailer.performance_review_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