Class: SpreeCmCommissioner::WaitingRoom::StampQueuePositions

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

Overview

Stamps queue positions onto waiting-guest Firestore docs so the app can render each guest's place in line ("N people ahead of you" = position - total_exited_queue). Walks the day partitions oldest-first, assigning each not-yet-stamped doc a continuous global position starting from the live current high-water mark (write-once — a doc is never restamped once it has a position), and commits in Firestore batches to stay under the 10 MiB/commit payload bound.

Also computes and publishes total_exited_queue here, in the same run as position, rather than in WaitingGuestsCaller (which only runs every 60s vs. this job's 10s). Both numbers feed the same app-side subtraction, so computing them from the same Firestore read window keeps them consistent with each other; splitting them across jobs on different cadences left up to ~50s where a freshly-stamped position was compared against a stale counter.

Constant Summary collapse

STAMP_LIMIT =
(ENV['WAITING_ROOM_POSITION_STAMP_LIMIT'] || 3000).to_i
FIRESTORE_BATCH_SIZE =

Firestore bounds a batch update by payload size (10 MiB); this batch size leaves 500/commit far under that.

(ENV['WAITING_ROOM_FIRESTORE_BATCH_SIZE'] || 500).to_i

Instance Method Summary collapse

Methods included from ServiceModuleThrowable

call!

Instance Method Details

#callObject



26
27
28
29
30
31
# File 'app/services/spree_cm_commissioner/waiting_room/stamp_queue_positions.rb', line 26

def call
  stamp_positions
  success(stamped: @stamped.to_i)
rescue StandardError => e
  failure(nil, e.message)
end