Class: SpreeCmCommissioner::VotingSessions::PublishToFirestore

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base, FirestoreConnection
Defined in:
app/services/spree_cm_commissioner/voting_sessions/publish_to_firestore.rb

Overview

Publishes a voting session's live state to Cloud Firestore so the show screen updates without a pull-to-refresh.

Firestore layout (already read by cm-market-vendor-app/hang_meas):

voting_sessions/{session_id}/meta/current        — session state + vote window
voting_sessions/{session_id}/contestants/current — reveal state, one entry per contestant

The meta/current field names match VotingSessionMetaModel.fromJson in packages/core/lib/core/models/spree/voting_session_meta_model.dart, kept in lockstep with this file — both sides changed together (vote_open_at/vote_close_at/paused replacing the original started_at/closes_at/paused_reason) specifically to stop colliding with VotingSessionSerializer/VotingSessionModel's own opens_at/closes_at, which mean the show's time slot, not the vote window. That parser ignores unknown keys, so the extra fields below (server_time, vote_duration_seconds) are safe to publish ahead of any Flutter change.

Note: this does NOT write voting_sessions/id/results/current — the live leaderboard the app also reads still has no Rails writer.

Instance Method Summary collapse

Methods included from FirestoreConnection

#firestore, #firestore_available?, #service_account

Instance Method Details

#call(voting_session:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/spree_cm_commissioner/voting_sessions/publish_to_firestore.rb', line 24

def call(voting_session:)
  return success(:skipped) unless firestore_available?

  session_document(voting_session).col('meta').doc('current').set(meta_payload(voting_session), merge: true)
  session_document(voting_session).col('contestants').doc('current').set(contestants_payload(voting_session), merge: true)

  success(voting_session)
rescue StandardError => e
  # A Firestore outage must not take the dashboard down with it: the session's own columns
  # are already committed and the REST API still serves the correct state, so the app
  # degrades to its pre-existing pull-to-refresh behaviour rather than breaking.
  Rails.logger.error("[VotingSessions::PublishToFirestore] session=#{voting_session.id} #{e.class}: #{e.message}")
  failure(nil, e.message)
end