feat(multiplayer): add regional allocation budget

This commit is contained in:
Josh Creek
2026-09-01 18:25:25 +01:00
parent c4c2ada1f6
commit 181a928c87
5 changed files with 146 additions and 1 deletions
+10
View File
@@ -26,10 +26,15 @@ type RosterPublisher interface {
PublishRoster(context.Context, domain.Assignment, []domain.SignedJoinAuthorisation, func([]byte, []byte) bool) error
}
type AllocationBudget interface {
Allow(region string, now time.Time) error
}
type Service struct {
Provider Provider
Durable Durable
Roster RosterPublisher
Budget AllocationBudget
Now func() time.Time
}
@@ -78,6 +83,11 @@ func (s Service) Allocate(ctx context.Context, request domain.AllocationRequest,
return agones.AllocatedServer{}, errNotConfigured
}
now := s.Now()
if s.Budget != nil {
if err := s.Budget.Allow(request.Region, now); err != nil {
return agones.AllocatedServer{}, err
}
}
result, err := s.Provider.Allocate(ctx, request, labels, now)
if err != nil {
return agones.AllocatedServer{}, err