Documentation ¶
Index ¶
- Variables
- func ContextLoop(getCtx ContextFunc, f lu.ProcessFunc, lo ...Option) lu.Process
- func ContextRetry(getCtx ContextFunc, f lu.ProcessFunc, callOpts ...Option) lu.Process
- func HTTP(name string, server *http.Server) lu.Process
- func Loop(f lu.ProcessFunc, lo ...Option) lu.Process
- func ManyReflexConsumers(awaitFunc AwaitRoleFunc, specs []reflex.Spec, ol ...Option) []lu.Process
- func NoOp() lu.Process
- func ReflexConsumer(awaitFunc AwaitRoleFunc, s reflex.Spec, ol ...Option) lu.Process
- func ReflexLiveConsumer(stream reflex.StreamFunc, consumer reflex.Consumer) lu.Process
- func Retry(f lu.ProcessFunc, lo ...Option) lu.Process
- func Scheduled(awaitFunc AwaitRoleFunc, curs Cursor, name string, when Schedule, ...) lu.Process
- func SecureHTTP(name string, server *http.Server, tlsCert, tlsKey string) lu.Process
- func ToTimezone(s cron.Schedule, tz *time.Location) cron.Schedule
- type AwaitRoleFunc
- type ContextFunc
- type Cursor
- type ErrorSleepFunc
- type EveryOption
- type Option
- func WithBreakableLoop() Option
- func WithClock(clock clock.Clock) Option
- func WithErrorSleep(d time.Duration) Option
- func WithErrorSleepFunc(f ErrorSleepFunc) Option
- func WithMaxErrors(v uint) Option
- func WithName(name string) Option
- func WithRole(role string) Option
- func WithSleep(d time.Duration) Option
- func WithSleepFunc(f SleepFunc) Option
- type RunFunc
- type Schedule
- type ScheduledFunc
- type SleepFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultBackoff = []uint{1, 2, 5, 10, 20, 50, 100}
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.
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 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 ¶
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 ReflexConsumer ¶
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 ¶
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 ¶
SecureHTTP integrates a secure http.Server as an App Process
func ToTimezone ¶
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 ¶
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 ErrorSleepFunc ¶
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 ¶
WithClock overwrites the clock field with the value provided. Mainly used during testing.
func WithErrorSleep ¶
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 ¶
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 WithRole ¶
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 ¶
WithSleep is a shortcut for WithSleepFunc + SleepFor. The process will sleep for `d` on every successful loop.
func WithSleepFunc ¶
WithSleepFunc sets the handler for determining how long ot sleep between loops when there was no 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)