Class: SpreeCmCommissioner::MaintenanceTasks::VotingSession

Inherits:
SpreeCmCommissioner::MaintenanceTask show all
Defined in:
app/models/spree_cm_commissioner/maintenance_tasks/voting_session.rb

Constant Summary

Constants inherited from SpreeCmCommissioner::MaintenanceTask

SpreeCmCommissioner::MaintenanceTask::MAX_ATTEMPTS

Instance Method Summary collapse

Methods inherited from SpreeCmCommissioner::MaintenanceTask

#async_execute, #execute

Instance Method Details

#maintainObject



18
19
20
21
22
# File 'app/models/spree_cm_commissioner/maintenance_tasks/voting_session.rb', line 18

def maintain
  ttl = rebuild_ttl
  SpreeCmCommissioner::VoteCounters::RebuildFromDb.call(voting_session_id: maintainable.id, ttl: ttl)
  SpreeCmCommissioner::VoteCounters::AuditCounters.call(voting_session_id: maintainable.id)
end

#rebuild_ttlObject

For closed sessions use the fixed 24h constant — closes_at is in the past so the dynamic formula would produce a TTL shorter than intended. For active sessions use closes_at + 24h buffer (same formula as Increment).



27
28
29
30
31
# File 'app/models/spree_cm_commissioner/maintenance_tasks/voting_session.rb', line 27

def rebuild_ttl
  return SpreeCmCommissioner::VoteCounters::Base::REDIS_KEY_TTL if maintainable.closed?

  [(maintainable.closes_at - Time.current).to_i + 1.day.to_i, 1].max
end