fleetqueue

package
v0.207.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 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

HTTP surface of the queue holder. Mounted by the fleet node ONLY when the operator sets fleet_queue_host (ADR 0030) — an unconfigured node serves none of these routes. Auth mirrors the fleet's bearer rule: when a fleet_auth_token is configured every queue route requires it (the queue carries agent contracts, the lane the fleet already tokens).

Package fleetqueue is the consolidated PULL queue — Option B of the 2026-08-26 decision, built DARK per the operator's 2026-08-28 direction: the code ships complete and tested, and stays inert until the operator binds the three config keys (ADR 0030). Option A's push path remains the default; nothing here runs on an unconfigured box.

Shape (from the decision doc): ONE node — config-elected, the always-on box — HOSTS the queue inside its existing fleet-node process (the established-exception daemon; no new process). Delegators SUBMIT; every claiming node — the holder included — pulls work it is eligible for. The store is durable (bbolt, already in-tree), so holder restarts lose nothing.

Semantics are AT-LEAST-ONCE by design: a claimed job whose lease expires returns to the queue, so a claimant that died mid-run is retried elsewhere — and one that merely stalled may complete a job that re-ran. Double EXECUTION is therefore possible at lease boundaries; double RESULT is not (the first ack wins, later acks are ignored). The lease is sized from the contract's own timeout plus slack to make the double-execution window a crashed-node event, not a slow-node event.

Index

Constants

View Source
const (
	// StateQueued .. StateFailed are the job lifecycle. Queued jobs are
	// claimable; claimed jobs run under a lease; done/failed are terminal.
	StateQueued  = "queued"
	StateClaimed = "claimed"
	StateDone    = "done"
	StateFailed  = "failed"
)

Variables

This section is empty.

Functions

func Mount

func Mount(mux Router, q *Queue, authOK func(*http.Request) bool)

Mount registers the queue routes on mux. authOK decides bearer acceptance (the fleet node passes its existing check so the two surfaces cannot drift).

Types

type Attribution

type Attribution struct {
	Asker    string
	PairCard string
	Origin   string
	RunClass string
}

Attribution is who submitted a job, whether the claiming node must card it, and the session and run class the work is for (see Job).

type Job

type Job struct {
	ID         string          `json:"id"`
	TaskType   string          `json:"task_type"`
	Payload    json.RawMessage `json:"payload"`
	TimeoutSec int             `json:"timeout_sec"`
	State      string          `json:"state"`
	Claimant   string          `json:"claimant,omitempty"`
	LeaseUntil int64           `json:"lease_until,omitempty"`
	Nacks      int             `json:"nacks"`
	Result     json.RawMessage `json:"result,omitempty"`
	Error      string          `json:"error,omitempty"`
	Submitted  int64           `json:"submitted"`
	// Asker and PairCard carry the submitter's attribution headers (core.AskerHeader and
	// core.PairCardHeader) to whichever node claims the job, so a pulled job behaves exactly like a
	// pushed one: the claiming node records who asked and, when PairCard is "node", cards the job
	// itself. Both are omitted on a job a pre-attribution submitter queued, which a claimant reads as
	// "nothing asked, nothing signalled".
	Asker    string `json:"asker,omitempty"`
	PairCard string `json:"pair_card,omitempty"`
	// Origin and RunClass carry the submitter's origin headers (core.OriginHeader and core.RunClassHeader,
	// cleaned) the same way (ADR 0087): the claiming node stamps them on its own ledger row, so a pulled job
	// names the session it worked for exactly like a pushed one. Omitted on a job a pre-0087 submitter queued,
	// which a claimant reads as "no session, no class named".
	Origin   string `json:"origin_session,omitempty"`
	RunClass string `json:"run_class,omitempty"`
}

Job is the stored envelope + lifecycle. Payload/TaskType mirror the push path's dispatch envelope exactly so a claiming node runs it through the SAME BuildRequest surface a pushed job uses.

type Queue

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

Queue is the durable store. All methods are safe for concurrent use; bbolt serializes writes and the mutex keeps read-modify-write transitions atomic at this layer's granularity.

func Open

func Open(path string) (*Queue, error)

Open opens (creating if absent) the queue store at path.

func (*Queue) Ack

func (q *Queue) Ack(id, nodeID string, result json.RawMessage, jobErr string) error

Ack finalizes a job with its result. First ack wins; a later ack (an expired-lease claimant finishing after the re-run) is ignored, never an error — at-least-once means late duplicates are expected, not exceptional.

func (*Queue) Claim

func (q *Queue) Claim(nodeID string, taskTypes []string) (job *Job, ok bool, err error)

Claim hands the oldest queued job whose task type the claimant declared to nodeID under a lease, or ok=false when nothing is claimable. Expired leases are reclaimed inline (no background reaper needed for correctness; ReapLeases exists to keep latency down between claims).

func (*Queue) Close

func (q *Queue) Close() error

Close closes the store.

func (*Queue) Depth

func (q *Queue) Depth() (int, error)

Depth counts non-terminal jobs (queued + claimed) — the holder's health datum.

func (*Queue) Get

func (q *Queue) Get(id string) (*Job, error)

Get returns the job view for result polling.

func (*Queue) Nack

func (q *Queue) Nack(id, nodeID, reason string) error

Nack returns a claimed job to the queue (the claimant could not run it — build failure, refused admission). Bounded by maxNacks, then failed.

func (*Queue) Submit

func (q *Queue) Submit(id, taskType string, payload json.RawMessage, timeoutSec int) (state string, err error)

Submit stores a new queued job. Idempotent on id: re-submitting an existing job (lost-ack retry) returns its current state without touching it.

func (*Queue) SubmitAttributed

func (q *Queue) SubmitAttributed(id, taskType string, payload json.RawMessage, timeoutSec int, a Attribution) (state string, err error)

SubmitAttributed is Submit for a submitter that names itself and signals who cards the job.

type Router

type Router interface {
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}

Router is what Mount registers the queue routes on: an *http.ServeMux, or anything that takes a pattern and a handler (the fleet node hands it a registrar that records the patterns, so a test can enumerate the routes it serves).

Jump to

Keyboard shortcuts

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