taskrun

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package taskrun runs one task under ledger admission: admit, claim, complete. It maps the caller work's result onto the ledger status and returns the work's own error. The caller supplies every value; the package holds no state between calls.

Map: taskrun.go = Options, Task, Run, and the sentinel errors. Rationale: ../docs/plans/taskrun.md. Contribution rules: ../AGENTS.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLedger reports a nil Options.Ledger.
	ErrNoLedger = errors.New("taskrun: ledger is required")
	// ErrNoOwner reports an empty Options.Owner.
	ErrNoOwner = errors.New("taskrun: owner is required")
	// ErrNoActor reports an empty Options.Actor.
	ErrNoActor = errors.New("taskrun: actor is required")
	// ErrNoLease reports a non-positive Options.Lease.
	ErrNoLease = errors.New("taskrun: lease must be positive")
	// ErrNoKey reports an empty Task.Key.
	ErrNoKey = errors.New("taskrun: task key is required")
	// ErrTaskDone reports a key already completed in the ledger.
	ErrTaskDone = errors.New("taskrun: task already completed")
	// ErrTaskFailed reports a key already failed in the ledger.
	ErrTaskFailed = errors.New("taskrun: task already failed")
	// ErrTaskBlocked reports a key already blocked in the ledger.
	ErrTaskBlocked = errors.New("taskrun: task blocked on a failed dependency")
)

Sentinel errors returned by Run during validation and replay.

Functions

func Run

func Run(ctx context.Context, opts Options, t Task, work func(context.Context) error) error

Run admits, claims, and completes one task around work. The returned error is the work's own error, unwrapped, when work ran. A task already terminal in the ledger returns its sentinel without running work. A Claim blocked by a live lease returns an error satisfying errors.Is(err, ledger.ErrLeaseActive). A Complete failure joins the returned error; the work result still leads.

A bounded Store adds one more outcome: it can delete the record between Admit and Claim, or after the lease expired while work still runs, so Run returns an error satisfying errors.Is(err, ledger.ErrNoKey). Do not merge that sentinel with taskrun.ErrNoKey, which means an empty Task.Key and is a caller error.

Types

type Options

type Options struct {
	Ledger *ledger.Ledger
	Actor  ledger.Actor
	Owner  ledger.OwnerID
	Lease  time.Duration
	Now    func() time.Time // defaults to time.Now
}

Options carries the ledger handle and the ceremony identity for one Run call. Every field is required except Now.

type Task

type Task struct {
	Key         ledger.IdempotencyKey
	Seq         ledger.Sequence
	Description string
	Needs       []ledger.IdempotencyKey
}

Task names one idempotent submission for Run to admit and run.

Jump to

Keyboard shortcuts

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