wrap

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package wrap supplies reusable cron.Wrapper decorators: panic recovery, timeouts, retry and overlap control. Install them with cron.WithChain or cron.WithEntryChain. A wrapper's state is created when it is applied at Add time, so one wrapper value installed globally still tracks each entry separately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelayIfRunning

func DelayIfRunning() cron.Wrapper

DelayIfRunning serializes invocations of one entry: an invocation that overlaps a running one waits for it to finish, then runs. A queued invocation returns ctx.Err() if its context is cancelled while waiting, and it holds its WithMaxConcurrent slot for the whole wait. Prefer SkipIfRunning when a late run is worthless.

func Recover

func Recover(opts ...Option) cron.Wrapper

Recover converts a panicking Job into an error ("cron: recovered panic: <value>") and logs the value and stack at error level. The scheduler already recovers job panics into cron.ErrJobPanic unless cron.WithoutRecover is set; use Recover to attach a custom logger, to recover inside an outer Retry so the panic is retried, or when running jobs outside the scheduler. The error does not wrap cron.ErrJobPanic.

func Retry

func Retry(p cron.RetryPolicy) cron.Wrapper

Retry is shorthand for p.Wrapper(), for use in cron.WithChain and cron.WithEntryChain lists. cron.WithRetry and cron.WithEntryRetry install the same wrapper innermost automatically.

func SkipIfRunning

func SkipIfRunning() cron.Wrapper

SkipIfRunning drops an invocation that overlaps a running one, returning cron.ErrAlreadyRunning without calling the job. State is created when the wrapper is applied at Add time, so one value installed with cron.WithChain still tracks each entry separately.

func Timeout

func Timeout(d time.Duration) cron.Wrapper

Timeout bounds one invocation to d, cancelling the job context with cron.ErrJobTimeout as the cause (see context.Cause). It is the wrapper form of cron.WithTimeout. A non-positive d returns the job unchanged.

Types

type Option

type Option func(*config)

Option configures Recover.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger Recover writes recovered panics to. The default is slog.Default(); a nil l keeps the default.

Jump to

Keyboard shortcuts

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