cancel

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 7 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 cancel receives the server's cancel signals for sqi-worker.

When a job or task is canceled on sqi-server the scheduler publishes a protocol.TaskCancelMsg for each run that was assigned or running, to the worker holding it. Subscribe receives those messages and routes each to the executor via TaskCanceler.Cancel.

Subject scheme

The server publishes to task.cancel.<workerID>, the subject of the worker holding the task. The worker subscribes once, before it asks for work, so a cancel committed after any lease it takes finds the subscription in place. The message names the task and, when the server stops one stale attempt rather than the task, the attempt (protocol.TaskCancelMsg.AttemptID).

Durability

A core subscription misses messages published while the worker is disconnected, and nothing on the worker reads the SQI_CANCEL stream's copy. The server repairs that from the worker's own reports: a "running" report for an attempt the server has closed is answered with a cancel naming it, and so is every heartbeat sweep while the worker's heartbeats still list the attempt. The same repairs cover a cancel that arrives between the lease reply and the executor recording the run, which finds no run to stop.

Usage

sub, err := cancel.Subscribe(nc, workerID, exec, logger)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Applies added in v0.4.0

func Applies(taskID, attemptID, runTaskID, runAttemptID string) bool

Applies reports whether a cancel naming taskID and attemptID applies to a run of attempt runAttemptID of task runTaskID: each name the cancel gives must match, and it must give at least one. TaskCanceler implementations use it to pick the runs a cancel stops.

func Subscribe added in v0.4.0

func Subscribe(nc natsConn, workerID string, canceler TaskCanceler, logger *slog.Logger) (*nats.Subscription, error)

Subscribe subscribes to workerID's task.cancel.<workerID> and delivers each cancel to canceler. It returns once the server has the subscription, so a worker that calls it before its first lease request receives every cancel for work it is leased while connected. The subscription lasts until it is unsubscribed or nc is closed, and nats.go restores it across reconnects.

Types

type TaskCanceler

type TaskCanceler interface {
	// Cancel requests cancellation of the task identified by taskID. A
	// non-empty attemptID limits it to that attempt: a run of another attempt
	// is left alone. An empty taskID with a non-empty attemptID stops that
	// attempt whatever its task (the server names no task for an attempt its
	// store has no record of). Returns true if a matching run was found and
	// cancellation was initiated, false otherwise (already finished, never
	// dispatched, or another attempt).
	Cancel(taskID, attemptID string) bool
}

TaskCanceler is implemented by the executor to cancel a specific in-progress task. [*executor.Executor] implements this interface.

Jump to

Keyboard shortcuts

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