Class: PickItemsSaveWorker
- Inherits:
-
Object
- Object
- PickItemsSaveWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/pick_items_save_worker.rb
Overview
Sidekiq worker: pick items save.
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/workers/pick_items_save_worker.rb', line 10 def perform( = {}) itemizable_type = [:itemizable_type] itemizable_id = [:itemizable_id] itemizable_params = [:itemizable_params] = [:version_timestamp] redirect_path = [:redirect_path] return_path = [:return_path] itemizable = itemizable_type.constantize.find(itemizable_id) total 5 at(1, 'Validating version timestamp...') # Check version timestamp to prevent concurrent edit conflicts if .to_i != itemizable.line_items.version store error_message: 'Line items were modified already by another save. Please reset and redo your changes.' store redirect_to: redirect_path return end at(2, 'Updating line items...') # Handle credit order negative quantities if itemizable.is_a?(Order) && itemizable.order_type == 'CO' itemizable_params[:line_items_attributes]&.each_value do |li_atr| li_atr[:quantity] = (li_atr[:quantity].to_i * -1).to_s if li_atr[:quantity].to_i.positive? end end ActiveRecord::Base.transaction do itemizable.update!(itemizable_params) itemizable.reload at(3, 'Synchronizing line items with rooms...') itemizable.synchronize_lines(nil, true) at(4, 'Checking for custom products and agreements...') itemizable.try(:set_custom_order_agreement) check_for_opm_and_unlinked_replacement_items(itemizable, ) itemizable.try(:update_linked_po_if_st) end at(5, 'Determining redirect path...') # Determine the appropriate redirect path final_redirect = determine_redirect_path(itemizable, return_path) store redirect_to: final_redirect store info_message: 'Line items saved successfully.' rescue StandardError => e error_msg = e.to_s if itemizable.respond_to?(:messaging_logs) error_msg2 = MessagingLog.(itemizable.messaging_logs) error_msg << ". #{error_msg2}" if error_msg2.present? end store error_message: error_msg&.first(1000) store redirect_to: redirect_path Rails.logger.error("PickItemsSaveWorker error for #{itemizable_type} #{itemizable_id}: #{e.}\n#{e.backtrace.join("\n")}") raise end |