Class: SpreeCmCommissioner::VotingSessionAutoCloseJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/spree_cm_commissioner/voting_session_auto_close_job.rb

Overview

Flips the Firestore state to closed once a manually-started vote window elapses.

Enqueued by VotingSessionTimingConcern#start_vote! with wait_until: vote_close_at. Vote rejection does not depend on this job — can_vote? already gates on the persisted vote_close_at — so a missed run costs a stale label in the app, never an accepted late vote.

Instance Method Summary collapse

Methods included from ApplicationJobDecorator

handle_deserialization_error, prepended

Instance Method Details

#perform(voting_session_id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/spree_cm_commissioner/voting_session_auto_close_job.rb', line 10

def perform(voting_session_id)
  voting_session = SpreeCmCommissioner::VotingSession.find_by(id: voting_session_id)
  return if voting_session.nil?

  # vote_close_at may have moved since this was scheduled (a restart, or the organizer
  # pressing Stop Vote and starting a new window). Only publish once the window has genuinely
  # elapsed; otherwise the run that matches the new vote_close_at will handle it.
  return if voting_session.vote_close_at.present? && Time.current < voting_session.vote_close_at

  SpreeCmCommissioner::VotingSessions::PublishToFirestore.call(voting_session: voting_session)
end