Class: SpreeCmCommissioner::OrderHolds::Hold

Inherits:
Object
  • Object
show all
Extended by:
ServiceModuleThrowable
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/order_holds/hold.rb

Overview

Orchestrates acquiring all applicable holds (seat blocks + inventory) for an order. Synchronizes the earliest expiry across both hold types to order.hold_expires_at for UI countdown.

Constant Summary collapse

UnableToHoldSeatsError =
Class.new(StandardError)
UnableToHoldInventoryError =
Class.new(StandardError)
HOLD_DURATION =
ENV.fetch('HOLD_DURATION_IN_MINUTES', '8').to_i.minutes

Instance Method Summary collapse

Methods included from ServiceModuleThrowable

call!

Instance Method Details

#call(order:, expires_at: HOLD_DURATION.from_now) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/spree_cm_commissioner/order_holds/hold.rb', line 14

def call(order:, expires_at: HOLD_DURATION.from_now)
  held_blocks = hold_seat_blocks!(order, expires_at)
  inventory_hold = acquire_inventory_hold!(order, expires_at)

  sync_hold_expires_at!(order, held_blocks, inventory_hold)

  CmAppLogger.log(
    label: "#{self.class.name}#call",
    data: {
      order_id: order.id,
      held_block_ids: held_blocks.map(&:id),
      inventory_hold_id: inventory_hold&.id,
      hold_expires_at: order.hold_expires_at
    }
  )

  success(order)
rescue StandardError => e
  error = { error_type: e.class.name.demodulize, order_id: order.id, message: e.message }
  CmAppLogger.error(label: "#{self.class.name}#call failed", data: error)
  failure(nil, error)
end