handoff

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package handoff is the crafting-brain executor's stock-handoff channel: a flock-guarded JSON queue file. The executor enqueues "holder gifts stock to recipient" instructions as it walks a craft plan; workers claim and complete the handoffs via send_gift. Mirrors pkg/rescue/queue.go's withLock mechanics (flock LOCK_EX sidecar, read-mutate-atomic-rename).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a handle on the shared queue file. Safe for concurrent use across processes: every operation takes an exclusive flock on a sidecar lock file (never renamed, so the lock identity is stable), then atomically rewrites the queue via temp+rename.

func NewQueue

func NewQueue(path string) *Queue

NewQueue returns a queue handle on path. The file need not exist yet.

func (*Queue) Enqueue

func (q *Queue) Enqueue(rec Record) (bool, error)

Enqueue appends rec (status pending, timestamps stamped) unless a record with the same ID already exists — one record per plan node, so re-planning while a handoff is in flight is a no-op.

func (*Queue) List

func (q *Queue) List() ([]Record, error)

List returns all records. A missing file is an empty queue; a corrupt file is an error (callers log and skip the tick rather than clobbering it).

func (*Queue) Remove

func (q *Queue) Remove(id string) (*Record, error)

Remove deletes the record with the given ID and returns it (nil if absent).

func (*Queue) Transition

func (q *Queue) Transition(id string, from, to Status, mutate func(*Record)) (bool, error)

Transition moves the record with the given ID from → to (compare-and-set; false when the record is absent or not in from), applying mutate to the record first.

type Record

type Record struct {
	ID          string `json:"id"`      // "<plan-id>/<node-id>" — unique per node
	Holder      string `json:"holder"`  // agent_id that owns the stock
	Station     string `json:"station"` // base_id where the stock sits
	ItemID      string `json:"item_id"`
	Qty         int    `json:"qty"`
	Recipient   string `json:"recipient"` // agent_id to send_gift to
	Status      Status `json:"status"`
	MovedQty    int    `json:"moved_qty"` // actually transferred (may be < Qty)
	Error       string `json:"error,omitempty"`
	RequestedAt string `json:"requested_at"`
	UpdatedAt   string `json:"updated_at"`
}

Record is one "holder gifts stock to recipient" instruction.

type Status

type Status string

Status is a handoff record's lifecycle state.

const (
	StatusPending Status = "pending"
	StatusDone    Status = "done"
	StatusFailed  Status = "failed"
)

Jump to

Keyboard shortcuts

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