Class: ExportRestaurantPackagesWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- ExportRestaurantPackagesWorker
- Includes:
- ActionView::Helpers::DateHelper, Sidekiq::Status::Worker
- Defined in:
- app/workers/export_restaurant_packages_worker.rb
Instance Attribute Summary collapse
-
#attachment ⇒ Object
Returns the value of attribute attachment.
-
#emails ⇒ Object
Returns the value of attribute emails.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Instance Attribute Details
#attachment ⇒ Object
Returns the value of attribute attachment.
6 7 8 |
# File 'app/workers/export_restaurant_packages_worker.rb', line 6 def @attachment end |
#emails ⇒ Object
Returns the value of attribute emails.
6 7 8 |
# File 'app/workers/export_restaurant_packages_worker.rb', line 6 def emails @emails end |
#job_id ⇒ Object
Returns the value of attribute job_id.
6 7 8 |
# File 'app/workers/export_restaurant_packages_worker.rb', line 6 def job_id @job_id end |
Instance Method Details
#perform(emails) ⇒ Object
8 9 10 11 12 13 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 |
# File 'app/workers/export_restaurant_packages_worker.rb', line 8 def perform(emails) I18n.with_locale :en do self.emails = Array.wrap(emails) total 100 store status: Attachment::ON_PROGRESS_STATUS store email_status: Attachment::PENDING_EMAIL_STATUS at 0 begin # Assign job ID self.job_id = self.jid filename = "restaurant_packages-#{Time.zone.now.to_i}.csv" filepath = Rails.root.join('tmp', filename) File.open(filepath, 'w') do |f| csv = [] generate_csv(csv) f.write csv.join end # Save the attachment and update the status (filepath) send_email store status: Attachment::DONE_STATUS at 100 # Clean up File.delete(filepath) if File.exist?(filepath) rescue StandardError => e APMErrorHandler.report(e) store status: Attachment::FAILED_STATUS raise e end end end |