Class: SpreeCmCommissioner::InventoryHolds::BulkReleaseStale

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

Direct Known Subclasses

BulkReleaseStalePaymentLocked

Constant Summary collapse

BATCH_SIZE =
100

Instance Method Summary collapse

Methods included from ServiceModuleThrowable

call!

Instance Method Details

#callObject



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
# File 'app/services/spree_cm_commissioner/inventory_holds/bulk_release_stale.rb', line 12

def call
  total = 0

  loop do
    # Lock these batches so that even if there are other processes, they will skip these rows and pick up other available ones,
    # ensuring the same holds aren't processed twice.
    holds = InventoryHold.transaction do
      scope.limit(BATCH_SIZE)
           .lock('FOR UPDATE SKIP LOCKED')
           .to_a
    end

    break if holds.empty?

    holds.each do |hold|
      result = SpreeCmCommissioner::InventoryHolds::Release.call(
        hold: hold,
        reason: reason,
        scheduled_release: true
      )

      total += 1 if result.success?
    end
  end

  success(released: total)
end

#reasonObject



10
# File 'app/services/spree_cm_commissioner/inventory_holds/bulk_release_stale.rb', line 10

def reason = :hold_expired

#scopeObject



9
# File 'app/services/spree_cm_commissioner/inventory_holds/bulk_release_stale.rb', line 9

def scope = InventoryHold.expired_active