executor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package executor runs one attempt of a job: it applies the job, kind or client timeout, recovers panics with their stack, consults the error handler, honours cancel requests, and maps the result to a completion.

ex, err := executor.New(executor.Config{Lookup: lookup, DefaultRetry: retry, Clock: clk})
completion, skip := ex.Execute(jobCtx, row)

Index

Constants

This section is empty.

Variables

View Source
var ErrNoWorker = job.ErrNoWorker

ErrNoWorker is the error recorded for jobs whose kind has no worker.

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Row *job.Row
	// contains filtered or unexported fields
}

Attempt is the per-attempt state reachable from the job context.

func AttemptFromContext

func AttemptFromContext(ctx context.Context) *Attempt

AttemptFromContext returns the attempt of the job running in ctx, or nil.

func (*Attempt) CompletedInTx

func (a *Attempt) CompletedInTx() bool

CompletedInTx reports whether MarkCompletedInTx was called.

func (*Attempt) MarkCompletedInTx

func (a *Attempt) MarkCompletedInTx()

MarkCompletedInTx records that Work completed the job in its own transaction (CompleteTx); the executor then skips its own completion when Work returns nil.

type Config

type Config struct {
	// Lookup returns the handler for a job kind.
	Lookup func(kind string) (Handler, bool)
	// DefaultTimeout applies when neither the job nor its kind sets one; 0 = none.
	DefaultTimeout time.Duration
	// DefaultRetry computes retry times when the kind has no policy.
	DefaultRetry RetryFunc
	// HandleError and HandlePanic may override the outcome of errors and panics.
	HandleError func(ctx context.Context, row *job.Row, err error) *job.Override
	HandlePanic func(ctx context.Context, row *job.Row, value any, trace string) *job.Override
	Clock       clock.Clock
	Logger      *slog.Logger
	// Observe is called after every attempt with the outcome kind and duration.
	Observe func(row *job.Row, outcome string, d time.Duration)
}

Config configures an Executor.

type Executor

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

Executor runs Work with a timeout and panic recovery and maps the result to a completion.

func New

func New(cfg Config) (*Executor, error)

New returns an Executor; Lookup, DefaultRetry and Clock are required.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, row *job.Row) (c job.Completion, skip bool)

Execute runs one attempt of row. ctx is the job context created by the producer; it is cancelled with cause job.ErrCancelRequested when an operator cancels the job. skip is true when the job was completed by CompleteTx and no completion must be written.

type Handler

type Handler struct {
	Work    WorkFunc
	Timeout time.Duration // 0 uses the client default
	Retry   RetryFunc     // nil uses the client default
}

Handler is the per-kind configuration resolved from registered workers.

type RetryFunc

type RetryFunc func(row *job.Row, now time.Time) time.Time

RetryFunc returns the next run time of a job that failed at now.

type WorkFunc

type WorkFunc func(ctx context.Context, row *job.Row) error

WorkFunc runs one attempt of a job.

Jump to

Keyboard shortcuts

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