process

package
v0.0.0-...-59daaa4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBackoff = []uint{1, 2, 5, 10, 20, 50, 100}
View Source
var ErrBreakContextLoop = errors.New("the context loop has been stopped", j.C("ERR_f3833d51676ea908"))

ErrBreakContextLoop acts as a translation error between the reflex domain and the lu process one. It will be returned as an alternative when (correctly configured) a reflex stream returns a reflex.ErrSteamToHead error.

View Source
var FixedInterval = Every

FixedInterval is deprecated. Deprecated: Use Every.

Functions

func ContextLoop

func ContextLoop(getCtx ContextFunc, f lu.ProcessFunc, lo ...Option) lu.Process

ContextLoop is a Process that will fetch a context and run f with that context. This can be used to block execution until a context is available.

func ContextRetry

func ContextRetry(
	getCtx ContextFunc,
	f lu.ProcessFunc,
	callOpts ...Option,
) lu.Process

ContextRetry runs the process function until it returns no error once.

func HTTP

func HTTP(name string, server *http.Server) lu.Process

HTTP integrates a http.Server as an App Process

func Loop

func Loop(f lu.ProcessFunc, lo ...Option) lu.Process

Loop is a Process that will repeatedly call f, logging errors until the process is cancelled.

func ManyReflexConsumers

func ManyReflexConsumers(awaitFunc AwaitRoleFunc, specs []reflex.Spec, ol ...Option) []lu.Process

ManyReflexConsumers allows you to take a number of (probably related) specs and ensure that they all run on the same service instance against a given role (and all with the same set of options). Unlike the other ReflexConsumer generating functions it returns a slice of lu.Process with a cardinality directly related the size of the supplied specs parameter.

func NoOp

func NoOp() lu.Process

NoOp is a Process which doesn't do anything but runs until the app is terminated.

func ReflexConsumer

func ReflexConsumer(awaitFunc AwaitRoleFunc, s reflex.Spec, ol ...Option) lu.Process

ReflexConsumer is the most standard function for generating a lu.Process that wraps a reflex consumer/stream loop. Unless you need the Particular temporary behaviour of a ReflexLiveConsumer or the multiplexing capability from a ManyReflexConsumer this should be your default choice to wait for a role, on a given consumer Spec, with any options that need to be defined.

func ReflexLiveConsumer

func ReflexLiveConsumer(stream reflex.StreamFunc, consumer reflex.Consumer) lu.Process

ReflexLiveConsumer will run a consumer on every instance of the service The stream will start from the latest event and the position is not restored on service restart.

func Retry

func Retry(f lu.ProcessFunc, lo ...Option) lu.Process

Retry runs the process function until it returns no error once.

func Scheduled

func Scheduled(awaitFunc AwaitRoleFunc, curs Cursor,
	name string, when Schedule, f ScheduledFunc,
	ol ...Option,
) lu.Process

Scheduled will create a lu.Process which executes according to a Schedule

func SecureHTTP

func SecureHTTP(name string, server *http.Server, tlsCert, tlsKey string) lu.Process

SecureHTTP integrates a secure http.Server as an App Process

func ToTimezone

func ToTimezone(s cron.Schedule, tz *time.Location) cron.Schedule

ToTimezone can be used when a schedule is to be run in a particular timezone. When using this with zones that observe daylight savings, it's important to be aware of the caveats around the boundaries of daylight savings - unit tests demonstrate times being skipped in some cases.

Types

type AwaitRoleFunc

type AwaitRoleFunc = func(role string) ContextFunc

type ContextFunc

type ContextFunc = func(ctx context.Context) (context.Context, context.CancelFunc, error)

ContextFunc should create a child context of ctx and return a cancellation function the cancel function will be called after the process has been executed TODO(adam): Offer a CancelCauseFunc option for cancelling the context

type Cursor

type Cursor interface {
	Get(ctx context.Context, name string) (string, error)
	Set(ctx context.Context, name string, value string) error
}

type ErrorSleepFunc

type ErrorSleepFunc func(errCount uint, err error) time.Duration

ErrorSleepFunc returns how long to sleep when we encounter an error `errCount` is how many times we've had an error, always > 0 `err` is the latest error

The function should not call time.Sleep itself, instead it should return the amount of time that will be used with lu.Wait

func ErrorSleepFor

func ErrorSleepFor(dur time.Duration) ErrorSleepFunc

ErrorSleepFor will return the same amount of time for every error

func MakeErrorSleepFunc

func MakeErrorSleepFunc(r uint, d time.Duration, backoff []uint) ErrorSleepFunc

MakeErrorSleepFunc specifies behaviour for how long to sleep when a function errors repeatedly. When error count is between 1 and r (1 <= c <= r) we will retry immediately. Then when error count is more than r, we will sleep for d. The backoff array is used as multipliers on d to determine the amount of sleep.

type EveryOption

type EveryOption func(s *intervalSchedule)

func WithDescription

func WithDescription(desc string) EveryOption

func WithOffset

func WithOffset(offset time.Duration) EveryOption

type Option

type Option func(*options)

func WithBreakableLoop

func WithBreakableLoop() Option

WithBreakableLoop sets a flag that determines if when an ErrBreakContextLoop is returned from a process function if that context loop itself can be allowed to terminate as well. EXPERIMENTAL: Added for the purposes of production testing isolated cases with the new breakable behaviour

func WithClock

func WithClock(clock clock.Clock) Option

WithClock overwrites the clock field with the value provided. Mainly used during testing.

func WithErrorSleep

func WithErrorSleep(d time.Duration) Option

WithErrorSleep is a shortcut for WithErrorSleepFunc + ErrorSleepFor The process will sleep for `d` on every error.

func WithErrorSleepFunc

func WithErrorSleepFunc(f ErrorSleepFunc) Option

WithErrorSleepFunc sets the handler for determining how long to sleep for after an error. You can use ErrorSleepFor to sleep for a fixed amount of time:

p := Loop(f, WithErrorSleepFunc(ErrorSleepFor(time.Minute)))

or you can use MakeErrorSleepFunc to get some more complex behaviour

p := Loop(f, WithErrorSleepFunc(MakeErrorSleepFunc(5, time.Minute, []uint{1,2,5,10})))

func WithMaxErrors

func WithMaxErrors(v uint) Option

WithMaxErrors sets the number errors that will cause us to give up on the currently running process. A value of 0 (the default) means we will never give up. A value of 1 means we give up after the first error, 2 the second and so on.

func WithName

func WithName(name string) Option

func WithRole

func WithRole(role string) Option

WithRole allows you to specify a custom role to await on when coordinating services which may be picked up by supporting lu Process builder like ReflexConsumer.

func WithSleep

func WithSleep(d time.Duration) Option

WithSleep is a shortcut for WithSleepFunc + SleepFor. The process will sleep for `d` on every successful loop.

func WithSleepFunc

func WithSleepFunc(f SleepFunc) Option

WithSleepFunc sets the handler for determining how long ot sleep between loops when there was no error.

type RunFunc

type RunFunc func(in context.Context, s reflex.Spec) error

type Schedule

type Schedule cron.Schedule

Schedule must return a time in the same time.Location as given to it in Next

func Every

func Every(period time.Duration, opts ...EveryOption) Schedule

Every returns a schedule which returns a time equally spaced with a period. e.g. if period is time.Hour and Offset is 5*time.Minute then this schedule will return 12:05, 13:05, 14:05, etc... The time is truncated to the period based on unix time (see time.Truncate for details)

func ParseCron

func ParseCron(cronStr string) (Schedule, error)

func Poll

func Poll(wait time.Duration) Schedule

Poll returns a schedule which runs on a given minimum delay (wait) between successful runs.

func TimeOfDay

func TimeOfDay(hour, minute int) Schedule

TimeOfDay returns a Schedule that will trigger at the same time every day hour is based on the 24-hour clock.

type ScheduledFunc

type ScheduledFunc func(ctx context.Context, lastRunTime, runTime time.Time, runID string) error

type SleepFunc

type SleepFunc func() time.Duration

SleepFunc returns how long to sleep between loops when there was no error.

func SleepFor

func SleepFor(dur time.Duration) SleepFunc

SleepFor returns a SleepFunc that returns a fixed sleep duration.

Jump to

Keyboard shortcuts

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