feat(multiplayer): add shared allocation quota

This commit is contained in:
Josh Creek
2026-09-01 18:38:06 +01:00
parent 55706ba9ea
commit 72e8d27633
11 changed files with 211 additions and 4 deletions
+15
View File
@@ -30,11 +30,16 @@ type AllocationBudget interface {
Allow(region string, now time.Time) error
}
type SharedAllocationQuota interface {
Consume(context.Context, string, time.Time) error
}
type Service struct {
Provider Provider
Durable Durable
Roster RosterPublisher
Budget AllocationBudget
Quota SharedAllocationQuota
Now func() time.Time
}
@@ -88,6 +93,11 @@ func (s Service) Allocate(ctx context.Context, request domain.AllocationRequest,
return agones.AllocatedServer{}, err
}
}
if s.Quota != nil {
if err := s.Quota.Consume(ctx, 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
@@ -102,6 +112,11 @@ func (s Service) RecordProviderAllocation(ctx context.Context, result agones.All
if s.Durable == nil || result.Allocation.State != domain.ServerAllocated || result.Endpoint == "" {
return domain.Allocation{}, domain.ErrAllocationInput
}
if s.Quota != nil {
if err := s.Quota.Consume(ctx, result.Allocation.Region, now); err != nil {
return domain.Allocation{}, err
}
}
return s.Durable.RecordProviderAllocation(ctx, result.Allocation, now)
}