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) GetByID(ctx context.Context, tenantID, id shared.ID) (*workorder.WorkOrder, error)
- func (s *Service) Issue(ctx context.Context, actor string, in IssueInput) (*workorder.WorkOrder, error)
- func (s *Service) Transition(ctx context.Context, actor string, tenantID, id shared.ID, to workorder.State, ...) 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 struct {
TenantID shared.ID
AssetID shared.ID
AgentID shared.ID
Capability string
AuthorizationID shared.ID
IdempotencyKey string
NotAfter time.Time
TimeBucket int64
}
IssueInput describes a work order to issue. TenantID must be non-empty (empty is DENY under RLS).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the work order use case.
func NewService ¶
func NewService(store ports.WorkOrderStore, signer ports.WorkOrderSigner, audit ports.AuditLogger, 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) GetByID ¶
func (s *Service) GetByID(ctx context.Context, tenantID, id shared.ID) (*workorder.WorkOrder, error)
GetByID returns the order or shared.ErrNotFound.
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) Transition ¶
func (s *Service) Transition(ctx context.Context, actor string, tenantID, id shared.ID, 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.