mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 18:32:05 +00:00
fix: rebuild candidate cache from queue authority
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user