mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat(multiplayer): add regional allocation budget
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user