mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat(multiplayer): run leased allocator worker
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
// AllocatingMatchClaims adapts the PostgreSQL lease boundary for allocator
|
||||
// workers without making the allocator package depend on the store package.
|
||||
type AllocatingMatchClaims struct {
|
||||
DB *sql.DB
|
||||
Transport string
|
||||
}
|
||||
|
||||
func (s AllocatingMatchClaims) ClaimAllocatingMatch(ctx context.Context, now time.Time) (domain.AllocationRequest, bool, error) {
|
||||
item, found, err := ClaimAllocatingMatch(ctx, s.DB, s.Transport, now)
|
||||
return item.Request, found, err
|
||||
}
|
||||
|
||||
func (s AllocatingMatchClaims) BindAllocatedMatch(ctx context.Context, allocation domain.Allocation) error {
|
||||
return BindAllocatedMatch(ctx, s.DB, allocation)
|
||||
}
|
||||
|
||||
// AllocationRegistry adapts provider-allocation reconciliation for allocator
|
||||
// workers. A successful provider response is not publishable until this store
|
||||
// boundary records the same compatibility tuple and GameServer identity.
|
||||
type AllocationRegistry struct{ DB *sql.DB }
|
||||
|
||||
func (s AllocationRegistry) RecordProviderAllocation(ctx context.Context, allocation domain.Allocation, now time.Time) (domain.Allocation, error) {
|
||||
return RecordProviderAllocation(ctx, s.DB, allocation, now)
|
||||
}
|
||||
Reference in New Issue
Block a user