routine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 11 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FN

type FN func(context.Context) error

FN is a routine function.

type PermanentError

type PermanentError struct{ Err error }

PermanentError is a permanent error that will cause a routine to immediately panic.

func NewPermanentError

func NewPermanentError(message string, args ...any) *PermanentError

NewPermanentError instantiates and returns a new permanent error.

func (*PermanentError) Error

func (e *PermanentError) Error() string

Error immplements the error interface.

func (*PermanentError) Is

func (e *PermanentError) Is(err error) bool

Is is used used by errors.Is() to match correctly.

type Routine

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

Routine is a wrapper around some function that needs to be executed in a loop in a go routine.

func New

func New(name string, fn FN) *Routine

New instantiates and return a new Routine.

func (*Routine) Close

func (r *Routine) Close()

Close closes this routine. It is a blocking call guaranteeing that the routine has exited its loop by the time it returns.

func (*Routine) HealthCheck

func (r *Routine) HealthCheck(ctx context.Context) error

Checks the health of this routine.

func (*Routine) OnPermanentError

func (r *Routine) OnPermanentError(fn func(error))

func (*Routine) Start

func (r *Routine) Start(ctx context.Context) *Routine

func (*Routine) WithConstantBackOff

func (r *Routine) WithConstantBackOff(seconds int) *Routine

WithConstantBackOff adds a constant backoff everytime a non permanent error is encountered.

func (*Routine) WithLogger

func (r *Routine) WithLogger(logger *slog.Logger) *Routine

func (*Routine) WithMaxConsecutiveErrors

func (r *Routine) WithMaxConsecutiveErrors(n int) *Routine

WithMaxConsecutiveErrors sets a max consecutive error threshold which, if exceeded, kills the routine.

func (*Routine) WithMetrics

func (r *Routine) WithMetrics() *Routine

WithMetrics

func (*Routine) WithSignal

func (r *Routine) WithSignal(channels ...<-chan struct{}) *Routine

WithSignal allows a signal to trigger a run of the routine function.

func (*Routine) WithStartupJitter

func (r *Routine) WithStartupJitter(d time.Duration) *Routine

WithStartupJitter adds a random delay before each execution to spread load.

func (*Routine) WithTicker

func (r *Routine) WithTicker(duration time.Duration) *Routine

func (*Routine) WithTimeout

func (r *Routine) WithTimeout(d time.Duration) *Routine

WithTimeout sets a timeout on the context for each execution of the routine's FN.

Jump to

Keyboard shortcuts

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