fix(multiplayer): recover recorded allocations

This commit is contained in:
Josh Creek
2026-09-01 10:40:10 +01:00
parent 55c46f56ec
commit 25fdc2c2c8
6 changed files with 68 additions and 12 deletions
+11 -3
View File
@@ -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