mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): recover recorded allocations
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
// lease a match before returning it and fence binding by allocation ID.
|
||||
type MatchClaimSource interface {
|
||||
ClaimAllocatingMatch(context.Context, time.Time) (domain.AllocationRequest, bool, error)
|
||||
FindProviderAllocation(context.Context, domain.AllocationRequest) (domain.Allocation, bool, error)
|
||||
BindAllocatedMatch(context.Context, domain.Allocation) error
|
||||
}
|
||||
|
||||
@@ -37,11 +38,18 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
|
||||
if err != nil || !found {
|
||||
return found, err
|
||||
}
|
||||
result, err := w.Service.Allocate(ctx, request, AllocationLabels(request))
|
||||
allocation, recorded, err := w.Claims.FindProviderAllocation(ctx, request)
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("allocate claimed match %s: %w", request.MatchID, err)
|
||||
return true, fmt.Errorf("recover allocation for match %s: %w", request.MatchID, err)
|
||||
}
|
||||
if err := w.Claims.BindAllocatedMatch(ctx, result.Allocation); err != nil {
|
||||
if !recorded {
|
||||
result, err := w.Service.Allocate(ctx, request, AllocationLabels(request))
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("allocate claimed match %s: %w", request.MatchID, err)
|
||||
}
|
||||
allocation = result.Allocation
|
||||
}
|
||||
if err := w.Claims.BindAllocatedMatch(ctx, allocation); err != nil {
|
||||
return true, fmt.Errorf("bind allocated match %s: %w", request.MatchID, err)
|
||||
}
|
||||
return true, nil
|
||||
|
||||
Reference in New Issue
Block a user