fix: bind matcher source to playlist

This commit is contained in:
Josh Creek
2026-09-01 09:35:00 +01:00
parent d0952adaf9
commit e170bcf0ef
4 changed files with 45 additions and 13 deletions
+5 -2
View File
@@ -10,7 +10,7 @@ import (
"github.com/cosmic-clash/cosmic-clash/server/domain"
)
type CandidateSource func(context.Context, time.Time, int) ([]domain.Candidate, error)
type CandidateSource func(context.Context, time.Time, domain.Playlist, int) ([]domain.Candidate, error)
type ProposalCreator interface {
CreateProposal(context.Context, domain.Proposal, map[string]string, time.Time) error
@@ -68,7 +68,7 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
return false, fmt.Errorf("invalid matcher size")
}
now := w.Now()
candidates, err := w.Source(ctx, now, w.Size)
candidates, err := w.Source(ctx, now, w.Playlist, w.Size)
if err != nil {
return false, err
}
@@ -77,6 +77,9 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
}
queue := domain.NewQueue()
for _, candidate := range candidates {
if candidate.Playlist != w.Playlist {
return false, fmt.Errorf("candidate playlist does not match worker")
}
if _, err := queue.Create(candidate.PlayerID, candidate.TicketID, "matcher-"+candidate.TicketID, candidate, now); err != nil {
return false, err
}