wire

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 11 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

Package wire holds the message formats shared by the engine and the SDKs beyond commands and events: worker jobs, dead letters and cache entries, plus the publish helpers that apply the claim-check and deduplication ids.

Index

Constants

View Source
const (
	HeaderMsgID       = "Nats-Msg-Id"
	HeaderTraceparent = "traceparent"
	HeaderProtocol    = "Pt-Protocol-Version"
)

Header names.

View Source
const (
	ReplyInvalid  = "invalid"
	ReplyRejected = "rejected"
	ReplyNotFound = "not_found"
	ReplyFailed   = "failed"
	ReplyConflict = "conflict"
)

Reply codes.

View Source
const (
	DLQCommand = "cmd"
	DLQJob     = "job"
	DLQTrigger = "trigger"
	// DLQDispatch records an event the dispatcher gave up on (its execution
	// is quarantined).
	DLQDispatch = "dispatch"
)

Dead-letter kinds.

View Source
const (
	// TimerExpire archives or deletes a terminal execution after its flow's
	// retention.
	TimerExpire = "archive"
	// TimerDelete deletes an execution: an archived one after its flow's
	// archive retention, or one whose deletion had to wait for the
	// deduplication window.
	TimerDelete = "delete"
)

Timer ids of the expiry of an execution. They are not flow timers: no timer command fires for them.

Variables

This section is empty.

Functions

func CmdID

func CmdID(execID, key string, gen, attempt int) string

CmdID derives the id of the command a worker sends for one attempt: a redelivered job produces the same id, so the stream deduplicates it.

func JobMsgID

func JobMsgID(execID, key string, gen, attempt int) string

JobMsgID is the deduplication id of one attempt of a task instance.

func PublishCmd

func PublishCmd(ctx context.Context, in *infra.Infra, c cmd.Command, traceparent string) error

PublishCmd publishes a command to its execution's partition, applying the claim-check and using the command id as the deduplication id (see msgID).

func PublishDLQ

func PublishDLQ(ctx context.Context, in *infra.Infra, d DeadLetter, dedup string) error

PublishDLQ records a dead letter. It is deduplicated per (kind, key, original subject sequence) so a crash between recording and terminating the original message does not record it twice.

func ScheduleCmd added in v1.0.1

func ScheduleCmd(ctx context.Context, in *infra.Infra, execID, timerID string, at time.Time, c cmd.Command) error

ScheduleCmd installs a one-shot JetStream schedule on the timer subject that publishes command c to the execution's command subject at time at. The schedule subject is a rollup, so re-installing it is idempotent.

func TraceIDs added in v1.0.3

func TraceIDs(traceparent string) (traceID, spanID string, ok bool)

TraceIDs returns the trace id and the parent (span) id of a W3C traceparent ("vv-<32 hex>-<16 hex>-<2 hex>"), for log keys. ok is false for an empty or malformed value, or one whose ids are all zero.

func TriggerStart

func TriggerStart(flow, execID string, data []byte) (cmd.Command, error)

TriggerStart is the start command a trigger of flow publishes for a message with body data, starting execID. A body that is not a JSON object is wrapped as {"data": …}.

Types

type CacheEntry

type CacheEntry struct {
	Output  json.RawMessage            `json:"output,omitempty"`
	Writes  map[string]json.RawMessage `json:"writes,omitempty"`
	Next    string                     `json:"next,omitempty"`
	Usage   map[string]float64         `json:"usage,omitempty"`
	Expires time.Time                  `json:"expires"`
}

CacheEntry is a cached task result.

type Concurrency

type Concurrency struct {
	Key string `json:"key"`
	Max int    `json:"max"`
}

Concurrency is a per-key concurrency limit a worker must honour.

type DeadLetter

type DeadLetter struct {
	Kind string `json:"kind"`
	Key  string `json:"key"`
	// Flow is the flow a trigger dead letter was meant to start.
	Flow       string              `json:"flow,omitempty"`
	Reason     string              `json:"reason"`
	Deliveries uint64              `json:"deliveries,omitempty"`
	Time       time.Time           `json:"time"`
	Subject    string              `json:"subject"`
	Header     map[string][]string `json:"header,omitempty"`
	Body       []byte              `json:"body,omitempty"`
	// Seq is the dead-letter stream sequence (set on read).
	Seq uint64 `json:"-"`
}

DeadLetter is a message the system gave up on.

type Job

type Job struct {
	ExecID     string          `json:"exec_id"`
	Flow       string          `json:"flow"`
	FlowHash   string          `json:"flow_hash"`
	Node       string          `json:"node"`
	Kind       string          `json:"kind"`
	Key        string          `json:"key"`
	Index      int             `json:"index,omitempty"`
	Generation int             `json:"generation"`
	Attempt    int             `json:"attempt"`
	Context    json.RawMessage `json:"context"`
	// Meta is the node's meta from the execution's flow version.
	Meta json.RawMessage `json:"meta,omitempty"`
	// Reply is the command subject the worker publishes its result to.
	Reply       string       `json:"reply"`
	CacheKey    string       `json:"cache_key,omitempty"`
	Concurrency *Concurrency `json:"concurrency,omitempty"`
	Traceparent string       `json:"traceparent,omitempty"`
}

Job is a unit of work for a worker of Kind.

type Progress

type Progress struct {
	ExecID     string          `json:"exec_id"`
	Node       string          `json:"node"`
	Key        string          `json:"key"`
	Generation int             `json:"generation"`
	Attempt    int             `json:"attempt"`
	Seq        int64           `json:"seq"`
	Time       time.Time       `json:"time"`
	Data       json.RawMessage `json:"data,omitempty"`
}

Progress is an intermediate result a worker publishes while it runs a job: core NATS, never written to the log, received only by clients already listening (G5-04). Seq counts the messages of one job attempt from 1.

type Reply

type Reply struct {
	OK  bool   `json:"ok"`
	Seq uint64 `json:"seq,omitempty"`
	// Joined marks a start that found its execution already there.
	Joined bool   `json:"joined,omitempty"`
	Code   string `json:"code,omitempty"`
	Error  string `json:"error,omitempty"`
}

Reply is the engine's answer to a command that carries a reply subject (cmd.Command.Reply), sent once the command is decided: OK with the sequence of the decision it produced (or of the last one, for a no-op), or a Code: "invalid" (malformed or does not fit the flow), "rejected" (refused in the execution's current state), "not_found", "failed" (dead-lettered).

type Stop

type Stop struct {
	ExecID string     `json:"exec_id"`
	All    bool       `json:"all,omitempty"`
	Tasks  []StopTask `json:"tasks,omitempty"`
}

Stop tells workers that running jobs of an execution are no longer wanted: every job of the execution (All: it ended) or the listed attempts (a task was cancelled, an attempt timed out). Published on core NATS by the dispatcher, best effort: a worker that misses it learns from the log head that the execution ended, and any late result is stale anyway (G5-02).

func (Stop) Matches

func (s Stop) Matches(key string, generation, attempt int) bool

Matches reports whether s stops the attempt of key.

type StopTask

type StopTask struct {
	Key        string `json:"key"`
	Generation int    `json:"generation"`
	Attempt    int    `json:"attempt"`
}

StopTask names one attempt to stop.

Jump to

Keyboard shortcuts

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