proxy-pool/internal/domain/ownership/ownership.go

36 lines
1.2 KiB
Go

package ownership
import (
"errors"
"time"
)
var (
ErrInvalidOwnership = errors.New("invalid proxy ownership request")
ErrOwnershipUnavailable = errors.New("proxy is unavailable for ownership")
ErrAlreadyOwned = errors.New("proxy is already owned")
ErrStaleAssignment = errors.New("proxy ownership assignment is stale")
ErrNotDraining = errors.New("proxy ownership is not draining")
ErrDrainNotReady = errors.New("proxy still has active or reserved runtime")
)
type Assignment struct {
ProxyID string
WorkerID string
Epoch uint64
Version uint64
ExpiresAt time.Time
Draining bool
}
// Repository is the shared authority for ownership changes. Implementations
// that also support extraction must serialize both operations transactionally.
type Repository interface {
Assign(now time.Time, proxyID, workerID string, ttl time.Duration) (Assignment, error)
Renew(now time.Time, proxyID, workerID string, epoch uint64, ttl time.Duration) (Assignment, error)
BeginDrain(proxyID, workerID string, epoch uint64) (Assignment, error)
AcknowledgeDrain(proxyID, workerID string, epoch uint64, active, reserved int64) error
Get(proxyID string) (Assignment, bool)
Expire(now time.Time) []Assignment
}