Class: EnterOrderRoomsWorker
- Inherits:
-
Object
- Object
- EnterOrderRoomsWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/enter_order_rooms_worker.rb
Overview
Sidekiq worker: enter order rooms.
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(options = {}) ⇒ Object
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 |
# File 'app/workers/enter_order_rooms_worker.rb', line 10 def perform( = {}) order_id = [:order_id] new_rc_ids = [:room_configuration_ids] || [] redirect_path = [:redirect_path] || "/orders/#{order_id}?tab=rooms" order = Order.find(order_id) total 3 at(1, 'Loading order and room configurations...') old_rc_ids = order.room_configuration_ids.uniq.sort Order.transaction do at(2, 'Assigning room configurations...') order.room_configuration_ids = new_rc_ids.uniq.sort new_rc_ids_sorted = order.room_configuration_ids at(3, 'Calculating shipping...') order.recalculate_shipping = true if old_rc_ids != new_rc_ids_sorted order.save! end store redirect_to: redirect_path store message: 'Room configurations updated successfully.' rescue StandardError => e store message: "Error updating rooms: #{e.}" store error_message: "Failed to update room configurations: #{e.}" store redirect_to: redirect_path Rails.logger.error("EnterOrderRoomsWorker error for order #{order_id}: #{e.}\n#{e.backtrace.join("\n")}") raise # AppSignal catches this automatically end |