Class: ShipmentReceiptsWorker
- Inherits:
-
Object
- Object
- ShipmentReceiptsWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/shipment_receipts_worker.rb
Overview
Sidekiq worker: shipment receipts.
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(options = {}) ⇒ 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 58 59 60 61 62 |
# File 'app/workers/shipment_receipts_worker.rb', line 14 def perform( = {}) shipment_receipt = ShipmentReceipt.new([:shipment_receipt]) purchase_order_shipment = PurchaseOrderShipment.find([:purchase_order_shipment_id]) shipment_items = [:shipment_items] shipment_receipt_saved = true total_steps = 5 # If shipment_items is empty then the shipment receipt will be invalid and won't save ShipmentReceipt.with_advisory_lock("receiving_items_pos_#{purchase_order_shipment.id}", timeout_seconds: 0) do total total_steps at(1, 'Creating shipment items') sleep 1 shipment_receipt.enter_receipts(shipment_items.stringify_keys) if purchase_order_shipment.estimated_landed_cost.present? total total_steps at(2, 'Calculating estimated landed cost') sleep 1 shipment_receipt.estimated_landed_cost = shipment_receipt.prorate_estimated_landed_cost shipment_receipt.currency = purchase_order_shipment.currency end total total_steps at(3, 'Creating shipment receipt') begin shipment_receipt_saved = shipment_receipt.save rescue ActiveRecord::StatementInvalid => e raise unless e..include?('locked delivery') Rails.logger.warn("[ShipmentReceiptsWorker] Skipping receipt for locked delivery (PO shipment #{purchase_order_shipment.id}): #{e.}") shipment_receipt_saved = false end at(4, 'Updating store items ') sleep 1 at(5, 'Finishing process') sleep 1 end = '<b>Create Shipment Receipt failed.</b>' if shipment_receipt_saved == false if shipment_receipt.persisted? if shipment_receipt.serial_number_state == "awaiting_assignment" store redirect_to: "/shipment_receipts/#{shipment_receipt.id}/assign_serial_numbers" else store redirect_to: "/purchase_orders/#{shipment_receipt.shipment_receipt_items.first.purchase_order.id}" end else store redirect_to: "/purchase_orders/new" end store message: end |