feat: add runnable casual matcher role

This commit is contained in:
Josh Creek
2026-09-01 09:32:22 +01:00
parent bdc89303b4
commit d0952adaf9
5 changed files with 131 additions and 3 deletions
+20
View File
@@ -34,6 +34,26 @@ type Worker struct {
Prepare PrepareFunc
}
// Run polls until cancellation. A failed attempt is returned so a supervisor
// can restart the role rather than silently dropping durable claim failures.
func (w Worker) Run(ctx context.Context, interval time.Duration) error {
if interval <= 0 {
return fmt.Errorf("matcher interval must be positive")
}
for {
if _, err := w.RunOnce(ctx); err != nil {
return err
}
timer := time.NewTimer(interval)
select {
case <-ctx.Done():
timer.Stop()
return nil
case <-timer.C:
}
}
}
// RunOnce performs one bounded matchmaking attempt. The source may be Redis
// backed, but the creator must be the durable transaction that claims tickets;
// a stale cache therefore fails safely and can be retried on the next pass.