Class: SpreeCmCommissioner::WaitingRoom::Admission::CallGuestsChunk

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

Overview

The actual per-guest admission work (session precreation + Firestore grant write) for one chunk claimed by CallGuests#claim_and_dispatch. Runs later, in its own CallGuestsChunkJob execution — not part of WaitingRoom::AdvanceQueue's shared-client tick — so it opens its own Firestore connection like any other standalone service.

Idempotent against Sidekiq redelivery, including a redelivery after a prior attempt already succeeded: re-reads current state (#get_all) and only grants docs still missing allow_to_enter_room_at, rather than trusting the job hasn't already run. precreate_sessions is separately idempotent (guest_identifier unique index + rescue). allow_at is passed in from the claiming tick rather than recomputed here, so even a write that races past the freshness check lands the same grant timestamp both times.

Constant Summary collapse

FIRESTORE_BATCH_SIZE =

Firestore bounds a batch update by payload size (10 MiB); 500 ops/commit leaves us far under that. Chunks are already CallGuests::CALL_CHUNK_SIZE (default 50), so this rarely matters in practice — kept for consistency with every other batched write in this subsystem.

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

Instance Method Summary collapse

Methods included from ServiceModuleThrowable

call!

Methods included from FirestoreConnection

#firestore, #firestore_available?, #service_account

Instance Method Details

#call(guest_refs:, allow_at:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/spree_cm_commissioner/waiting_room/admission/call_guests_chunk.rb', line 25

def call(guest_refs:, allow_at:)
  pending = firestore.get_all(guest_refs).select { |document| document.data&.dig(:allow_to_enter_room_at).nil? }

  if pending.any?
    sessions_by_guest_id = precreate_sessions(pending)
    grant_all(pending, sessions_by_guest_id, allow_at)
  end

  success(granted_count: pending.size)
rescue StandardError => e
  failure(nil, e.message)
end