fix: rebuild candidate cache from queue authority

This commit is contained in:
Josh Creek
2026-08-31 22:12:03 +01:00
parent 4c131db2ca
commit a45d2ddbb7
3 changed files with 39 additions and 1 deletions
+11
View File
@@ -20,6 +20,17 @@ func NewCandidateCache() *CandidateCache {
return &CandidateCache{candidates: make(map[string]domain.Candidate)}
}
// RebuildFromQueue is the safe restart/failover path for the cache. Queue
// expiry and state filtering happen at the authoritative source before the
// cache is atomically replaced; callers never have to reconstruct those
// rules from a stale Redis index.
func RebuildFromQueue(cache *CandidateCache, queue *domain.Queue, now time.Time) error {
if cache == nil || queue == nil || now.IsZero() {
return fmt.Errorf("invalid candidate rebuild arguments")
}
return cache.Rebuild(queue.Candidates(now))
}
func (c *CandidateCache) Upsert(candidate domain.Candidate) error {
if candidate.TicketID == "" || candidate.PlayerID == "" || candidate.EnqueuedAt.IsZero() {
return fmt.Errorf("invalid candidate")