Class: SpreeCmCommissioner::WaitingRoom::Heartbeat::Sweep
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::WaitingRoom::Heartbeat::Sweep
- Extended by:
- ServiceModuleThrowable
- Includes:
- Spree::ServiceModule::Base, FirestoreConnection
- Defined in:
- app/services/spree_cm_commissioner/waiting_room/heartbeat/sweep.rb
Overview
Marks a waiting-guest doc left_at once its client-refreshed last_ping_at goes stale — a guest who abandoned the queue without tapping "Leave" (backgrounded, force-quit, uninstalled). Runs first in WaitingRoom::AdvanceQueue, before Positions::Stamp and Admission::CallGuests read anything: a stale doc resolved here frees both a position for Positions::Stamp's frontier_position to advance past and a call slot Admission::CallGuests would otherwise spend on a guest who is already gone.
Not housekeeping — this is what lets frontier_position advance at all: an abandoned doc that never resolves freezes the count for every guest behind it.
Contributes no lobby fields of its own (lobby: is always empty) — only telemetry
(logs:) — but returns both for consistency with the other WaitingRoom::AdvanceQueue steps.
Constant Summary collapse
- HEARTBEAT_TTL_SECONDS =
A doc whose client-refreshed last_ping_at is older than this is swept (marked left_at) — which costs the guest their queue position, so it's deliberately generous: paired with the app's ~20s heartbeat interval, a genuinely live guest tolerates roughly a phone-call's worth of missed pings before losing their spot.
(ENV['WAITING_ROOM_HEARTBEAT_TTL_SECONDS'] || 180).to_i
- SWEEP_LIMIT =
Per-partition cap on how many stale docs one run reaps. Self-healing if exceeded (the rest go next run, 10s later) — a delayed sweep only delays how quickly frontier_position advances past a phantom, it never lets it outrun the true high-water mark.
(ENV['WAITING_ROOM_SWEEP_LIMIT'] || 1000).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
Methods included from FirestoreConnection
#firestore, #firestore_available?, #service_account
Instance Method Details
#call(firestore: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/spree_cm_commissioner/waiting_room/heartbeat/sweep.rb', line 35 def call(firestore: nil) started_at = Time.zone.now @firestore = firestore if firestore.present? swept = sweep_paths.sum { |path| sweep_abandoned(path) } success( swept: swept, lobby: {}, logs: { swept_count: swept, started_at: started_at, finished_at: Time.zone.now } ) rescue StandardError => e failure(nil, e.) end |