Class: SpreeCmCommissioner::WaitingRoom::PublishLobbyPath

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

Overview

Publishes the server-owned waiting-guests records path to the lobby document, so mobile and the waiting-room caller share one source of truth for the date partition instead of each building it from their own (possibly skewed) clock/timezone.

CRON note: ecause we use Time.zone.now to determine the path, it’s important that the CRON job runs at the same timezone as well — otherwise the cron could fire before/after Time.zone.now rolls to the new date. Example: cron: “0 0 * * * Asia/Phnom_Penh”

Caching note: No caching needed since the service is expected to be called once per day so a single daily merge write is negligible.

Instance Method Summary collapse

Methods included from ServiceModuleThrowable

call!

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/spree_cm_commissioner/waiting_room/publish_lobby_path.rb', line 19

def call
  # merge: true so we never clobber the lobby's `full` / `available_slots` fields, and it
  # deep-merges the nested `logs` map so each job keeps its own namespaced key.
  # logs.publish_lobby_path_job.last_published_at is a point-in-time heartbeat: it confirms
  # the 5-min publisher cron is alive and (with the path above) shows the date partition.
  lobby_document.set(
    {
      waiting_guests_records_path: records_path,
      logs: { publish_lobby_path_job: { last_published_at: Time.zone.now } }
    },
    merge: true
  )

  success(records_path: records_path)
rescue StandardError => e
  failure(nil, e.message)
end