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 ¶
var ErrNoWorker = job.ErrNoWorker
ErrNoWorker is the error recorded for jobs whose kind has no worker.
Functions ¶
This section is empty.
Types ¶
type Attempt ¶
Attempt is the per-attempt state reachable from the job context.
func AttemptFromContext ¶
AttemptFromContext returns the attempt of the job running in ctx, or nil.
func (*Attempt) CompletedInTx ¶
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.
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.