Class: SpreeCmCommissioner::InventoryHolds::BulkReleaseStale
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::InventoryHolds::BulkReleaseStale
show all
- Extended by:
- ServiceModuleThrowable
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/inventory_holds/bulk_release_stale.rb
Constant Summary
collapse
- BATCH_SIZE =
100
Instance Method Summary
collapse
call!
Instance Method Details
#call ⇒ Object
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
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
|
#reason ⇒ Object
10
|
# File 'app/services/spree_cm_commissioner/inventory_holds/bulk_release_stale.rb', line 10
def reason = :hold_expired
|
#scope ⇒ Object
9
|
# File 'app/services/spree_cm_commissioner/inventory_holds/bulk_release_stale.rb', line 9
def scope = InventoryHold.expired_active
|