mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 13:22:03 +00:00
feat: add runnable casual matcher role
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user