Class: SpreeCmCommissioner::AsyncOperations::SeatLock
- Inherits:
-
SpreeCmCommissioner::AsyncOperation
- Object
- Spree::Base
- Base
- SpreeCmCommissioner::AsyncOperation
- SpreeCmCommissioner::AsyncOperations::SeatLock
- Defined in:
- app/models/spree_cm_commissioner/async_operations/seat_lock.rb
Overview
One operator submission of the "Lock Seats" drawer.
Stores the DESIRED state (which seats should end up locked across which dates), not a diff. The diff against what is currently locked is computed by Seats::ApplyLocks at perform time, so it works from fresh data rather than a snapshot taken when the drawer was rendered.
Constant Summary collapse
- SKIPPED_SAMPLE_LIMIT =
Skips are summarised rather than listed. each_block_date emits a :no_inventory skip for every pair with no inventory item, so an ordinary action -- 31 dates selected where only 10 have inventory, 40 seats -- produces 840 entries. A reason->count hash plus a small sample is both a row that stays small and the only version an operator can actually read.
20
Constants inherited from SpreeCmCommissioner::AsyncOperation
SpreeCmCommissioner::AsyncOperation::ERROR_LIMIT
Instance Method Summary collapse
- #any_skips? ⇒ Boolean
- #process! ⇒ Object
- #skipped_count ⇒ Object
-
#track!(locked: 0, unlocked: 0, skips: []) ⇒ Object
One UPDATE per service call rather than per seat-date.
Methods inherited from SpreeCmCommissioner::AsyncOperation
#enqueue, #fail!, #finish!, #in_progress?, #stale?, #start!, #timeout
Instance Method Details
#any_skips? ⇒ Boolean
36 37 38 |
# File 'app/models/spree_cm_commissioner/async_operations/seat_lock.rb', line 36 def any_skips? skipped_count.positive? end |
#process! ⇒ Object
28 29 30 |
# File 'app/models/spree_cm_commissioner/async_operations/seat_lock.rb', line 28 def process! SpreeCmCommissioner::Seats::ApplyLocks.call!(operation: self) end |
#skipped_count ⇒ Object
32 33 34 |
# File 'app/models/spree_cm_commissioner/async_operations/seat_lock.rb', line 32 def skipped_count skipped_summary.values.sum(&:to_i) end |
#track!(locked: 0, unlocked: 0, skips: []) ⇒ Object
One UPDATE per service call rather than per seat-date. Doubles as the stale? heartbeat, so a long run never looks like a dead worker.
Reassigns every jsonb-backed value: ActiveRecord::Store does not dirty-track in-place mutation,
so skipped_samples << x would be silently lost on save.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/spree_cm_commissioner/async_operations/seat_lock.rb', line 45 def track!(locked: 0, unlocked: 0, skips: []) # Stringify once, on the way in. The services hand over symbol-keyed hashes but jsonb round-trips # them to string keys, so without this the same record reads differently before and after a # reload -- and every consumer would have to check both. entries = skips.map { |skip| skip.transform_keys(&:to_s) } self.locked_count = locked_count + locked self.unlocked_count = unlocked_count + unlocked self.skipped_summary = merge_skipped_summary(entries) self.skipped_samples = (skipped_samples + sample_room(entries)).first(SKIPPED_SAMPLE_LIMIT) save! end |