Documentation
¶
Overview ¶
Package fleetwork is the use-case layer for the fleet work order lifecycle (#407, epic #405): issue a signed, addressed, authorised order; let an agent claim orders addressed to it; and drive orders through the validated state machine. It audits every mutation and keeps the domain pure. The store enforces tenant isolation (RLS), idempotency and the in-flight uniqueness guard; this layer signs, validates transitions, and audits.
Index ¶
- type IssueInput
- type Service
- func (s *Service) Claim(ctx context.Context, actor string, tenantID, agentID shared.ID, max int) ([]*workorder.WorkOrder, error)
- func (s *Service) CompleteResponse(ctx context.Context, actor string, tenantID, id shared.ID, ...) error
- func (s *Service) FenceResponses(ctx context.Context, actor string, tenantID shared.ID, generation int64, ...) error
- func (s *Service) GetByID(ctx context.Context, tenantID, id shared.ID) (*workorder.WorkOrder, error)
- func (s *Service) GetByIdempotencyKey(ctx context.Context, tenantID shared.ID, idempotencyKey string) (*workorder.WorkOrder, error)
- func (s *Service) Issue(ctx context.Context, actor string, in IssueInput) (*workorder.WorkOrder, error)
- func (s *Service) SetExecutionAuthorizer(guard ports.ExecutionAuthorizer)
- func (s *Service) Transition(ctx context.Context, actor string, tenantID, id shared.ID, leaseID string, ...) error
- func (s *Service) Verify(wo *workorder.WorkOrder) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IssueInput ¶
type IssueInput = ports.FleetWorkIssueInput
IssueInput remains an alias for compatibility; the issuance DTO lives in ports.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the work order use case.
func NewService ¶
func NewService(store ports.WorkOrderAuditStore, signer ports.WorkOrderSigner, audit ports.IdempotentAuditLogger, clock ports.Clock, ids ports.IDGenerator) (*Service, error)
NewService validates its dependencies and returns the service.
func (*Service) Claim ¶
func (s *Service) Claim(ctx context.Context, actor string, tenantID, agentID shared.ID, max int) ([]*workorder.WorkOrder, error)
Claim atomically claims up to max unexpired orders addressed to agentID, moving them from issued to claimed, and audits each claim.
func (*Service) CompleteResponse ¶ added in v0.2.0
func (s *Service) CompleteResponse(ctx context.Context, actor string, tenantID, id shared.ID, result fleetagent.ResponseExecutionResult, reason string) error
CompleteResponse persists a lease-bound endpoint execution result and its terminal work-order state atomically. The result records application only; independent telemetry still verifies effect.
func (*Service) FenceResponses ¶ added in v0.2.0
func (s *Service) FenceResponses(ctx context.Context, actor string, tenantID shared.ID, generation int64, reason string) error
FenceResponses cancels every live effect command below a durable tenant halt generation.
func (*Service) GetByID ¶
func (s *Service) GetByID(ctx context.Context, tenantID, id shared.ID) (*workorder.WorkOrder, error)
GetByID returns the order or shared.ErrNotFound.
func (*Service) GetByIdempotencyKey ¶ added in v0.2.0
func (*Service) Issue ¶
func (s *Service) Issue(ctx context.Context, actor string, in IssueInput) (*workorder.WorkOrder, error)
Issue builds, signs and persists a work order. It is idempotent by (tenant, idempotency key): re-issuing returns the existing order. A second live order for the same (tenant, asset, capability, time bucket) is rejected by the store with shared.ErrConflict.
func (*Service) SetExecutionAuthorizer ¶ added in v0.2.0
func (s *Service) SetExecutionAuthorizer(guard ports.ExecutionAuthorizer)
SetExecutionAuthorizer installs the current-state guard used at the endpoint execution boundary.
func (*Service) Transition ¶
func (s *Service) Transition(ctx context.Context, actor string, tenantID, id shared.ID, leaseID string, to workorder.State, reason string) error
Transition moves an order to a new state after validating the transition is legal for its current state, using an optimistic expected-state check in the store. reason is required for a refusal.