Documentation
¶
Overview ¶
Package status implements the typed task-status publisher for sqi-worker.
A Publisher sends the status reports the worker owes the server for each attempt it runs: the attempt's first "running" and its terminal status ("succeeded", "failed", "canceled", or a "failed" carrying protocol.MessageWorkerShutdown). Each goes to the task.status.<workerID>.<job> subject through a Transport that returns only once the SQI_TASK stream has stored it. Progress snapshots and any later "running" are not sent here: the OpenJD interceptor (internal/worker/openjd) publishes those best-effort with core NATS.
Acknowledgement and retry ¶
Every report carries a Nats-Msg-Id of "<attemptID>:<kind>", where kind is running, succeeded, failed, canceled or shutdown, so a retry of a report the stream already stored is dropped by the stream's de-duplication window, and a run's own "failed" and a shutdown "failed" for one attempt do not de-duplicate each other.
The first try runs inline, bounded by Config.AckTimeout, so a report the broker takes at once is stored before the caller moves on, and a broker that does not answer costs the caller at most one AckTimeout. A report that is not acknowledged stays pending and is retried in the background with exponential backoff from Config.RetryBase to Config.RetryMax, with no limit on tries, until it is stored or Publisher.Flush drops it. Only a failure no retry can cure is logged at Error and dropped at once: a marshal failure, a message over the broker's maximum payload, or a closed connection, which never reopens. A publish the broker denies surfaces as an ack timeout and is retried like any other. A terminal report drops a still-pending "running" for the same attempt, since a terminal status is legal on an assigned task and a later "running" would be refused as stale.
Publisher.PendingAttemptIDs names the attempts with a report still pending, and Publisher.WithPending adds them to the attempts a worker holds, so its heartbeats keep listing them. Publisher.Flush waits for the pending reports at shutdown, and Publisher.Abandon drops them without waiting.
Fields ¶
Every message carries worker_id from Config.WorkerID. A terminal report also carries ended_ago_ms, how long ago the task ended by the worker's monotonic clock, measured again on every try, from which the server places the end on its own timeline.
Index ¶
- Constants
- type Config
- type Publisher
- func (p *Publisher) Abandon() (dropped int)
- func (p *Publisher) Flush(ctx context.Context) (dropped int)
- func (p *Publisher) PendingAttemptIDs() []string
- func (p *Publisher) Running(msg *protocol.AssignMsg, sessionID string, at time.Time)
- func (p *Publisher) Terminal(msg *protocol.AssignMsg, sessionID, status string, exitCode *int, ...)
- func (p *Publisher) WithPending(held []string) []string
- type Transport
Constants ¶
const DefaultAckTimeout = 2 * time.Second
DefaultAckTimeout is Config.AckTimeout when it is left zero. It bounds the inline try of a terminal status a task hands over after the shutdown drain, so it is part of the worker's shutdown budget.
const DefaultFlushTimeout = 10 * time.Second
DefaultFlushTimeout is how long a worker's graceful shutdown waits in Publisher.Flush for the reports still pending after its drain. It is separate from the drain's grace period, which is spent by then, and part of the worker's shutdown budget.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// WorkerID is embedded in every outgoing status message.
WorkerID string
// AckTimeout bounds each try, the wait for the stream's ack included.
// Default: 2 s.
AckTimeout time.Duration
// RetryBase is the wait before the first retry; each later wait doubles,
// up to RetryMax. Default: 250 ms.
RetryBase time.Duration
// RetryMax caps the wait between retries. Default: 5 s.
RetryMax time.Duration
// WireOffset is added to the At timestamp of every message, and to
// nothing else: ended_ago_ms is still measured on the real clock. It is
// zero on a real worker; sqi-load sets it to simulate a worker whose
// clock is skewed.
WireOffset time.Duration
}
Config holds tunable parameters for a Publisher. Zero-value durations are replaced with package defaults when New is called.
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher sends task-status reports and retries each until the SQI_TASK stream acknowledges it.
Publisher is safe for concurrent use from multiple goroutines.
func New ¶
New returns a ready-to-use Publisher. Any zero or negative durations in cfg are replaced with defaults before use.
func (*Publisher) Abandon ¶ added in v0.4.0
Abandon stops and drops every report still pending without waiting for any, logging one Warn for each, and returns how many it dropped. It is for a worker that ends without finishing its sends. Reports handed over after Abandon returns are sent as usual.
func (*Publisher) Flush ¶ added in v0.4.0
Flush waits until no report is pending or ctx ends. If ctx ends first, it stops and drops every report still pending, logging one Warn for each, and returns how many it dropped. Reports handed over after Flush returns are sent as usual.
func (*Publisher) PendingAttemptIDs ¶ added in v0.4.0
PendingAttemptIDs returns the attempts with a report not yet acknowledged, sorted and de-duplicated.
func (*Publisher) Running ¶
Running reports an attempt's first "running", at the time the task was started. It returns once the stream has stored the report or its first try has failed; a failed report is retried in the background.
func (*Publisher) Terminal ¶
func (p *Publisher) Terminal( msg *protocol.AssignMsg, sessionID, status string, exitCode *int, failureReason string, lastProgress *int, endedAt time.Time, )
Terminal reports an attempt's terminal status: "succeeded", "failed", or "canceled". It returns once the stream has stored the report or its first try has failed; a failed report is retried in the background. A "running" for the same attempt that is still pending is dropped.
exitCode should be nil where no exit code is meaningful (a canceled or never-started process). failureReason becomes the message's Message; a "failed" whose reason is protocol.MessageWorkerShutdown is the worker giving the attempt back. lastProgress is the most-recently seen openjd_progress value, or nil. endedAt is when the task ended; it must keep its monotonic clock reading (do not pass it through UTC, Round or JSON), since ended_ago_ms is measured from it on every try. A zero endedAt is taken as the time of the call.
func (*Publisher) WithPending ¶ added in v0.4.0
WithPending returns held together with the attempts that have a report not yet acknowledged, sorted and de-duplicated: the attempts a worker's heartbeat lists. The server reclaims an open attempt once heartbeats stop listing it, so one whose terminal report is still being retried must stay listed after the worker has released it. WithPending may reuse held's backing array.