fleetwork

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

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.

func (*Service) Verify

func (s *Service) Verify(wo *workorder.WorkOrder) bool

Verify reports whether the order's signature matches its current authorising fields. The agent runtime (a later issue) uses this before acting; exposed here so the signing contract is testable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL