Class: VoidRmasWorker
- Inherits:
-
Object
- Object
- VoidRmasWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/void_rmas_worker.rb
Overview
Sidekiq worker: void rmas.
Instance Method Summary collapse
-
#perform ⇒ Object
Runs the job.
Instance Method Details
#perform ⇒ Object
Runs the job.
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 |
# File 'app/workers/void_rmas_worker.rb', line 12 def perform # System-actor whodunnit (the playbook pattern, cf. # Maintenance::RmaMaintenance): auto-voids must show up in the audit # trail with an actor, not a NULL whodunnit. PaperTrail.request(whodunnit: 'VoidRmasWorker') do three_months_old = Date.current.months_ago(3).to_time week_old = Date.current.weeks_ago(1).to_time # void rmas under awaiting return state and are more than 3 months old. old_rmas_on_awaiting_return = Rma.where(state: 'awaiting_return').where(company_id: [1, 2]).where(created_at: ...three_months_old) if old_rmas_on_awaiting_return.present? old_rmas_on_awaiting_return.each do |rma| rma.void_all_items_and_self rescue StandardError => e ErrorReporting.error e, rma_id: rma.id end end # void rmas under requested state and are more than 7 days old. old_rmas_on_requested = Rma.where(state: 'requested').where(created_at: ...week_old) return if old_rmas_on_requested.blank? old_rmas_on_requested.each do |rma| rma.void_all_items_and_self rescue StandardError => e ErrorReporting.error e, rma_id: rma.id end end end |