guard

package
v2.0.0-...-072ea80 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package guard contains middleware capable to protect execution of flow from crashing or from unpredicted behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cancel

func Cancel(data interface{}) floc.Job

Cancel cancels execution of the flow with the data given.

func Complete

func Complete(data interface{}) floc.Job

Complete completes execution of the flow with the data given.

func Deadline

func Deadline(when WhenDeadlineFunc, id interface{}, job floc.Job) floc.Job

Deadline protects the job from doing the job after the deadline. The job is run in it's own goroutine while the current goroutine waits until the job finished or the deadline came or the flow is finished.

func Fail

func Fail(data interface{}, err error) floc.Job

Fail cancels execution of the flow with the data and error given.

func IgnorePanic

func IgnorePanic(job floc.Job) floc.Job

IgnorePanic protects the job from falling into panic. On panic the panic will be ignored. Guarding the job from falling into panic is effective only if the job runs in the current goroutine.

func OnDeadline

func OnDeadline(when WhenDeadlineFunc, id interface{}, job floc.Job, timeoutTrigger TimeoutTrigger) floc.Job

OnDeadline protects the job from doing the job after deadline. In addition it takes TimeoutTrigger func which called if time is out. The job is run in it's own goroutine while the current goroutine waits until the job finished or the deadline came or the flow is finished.

func OnPanic

func OnPanic(job floc.Job, panicTrigger PanicTrigger) floc.Job

OnPanic protects the job from falling into panic. In addition it takes PanicTrigger func which is called in case of panic. Guarding the job from falling into panic is effective only if the job runs in the current goroutine.

func OnTimeout

func OnTimeout(when WhenTimeoutFunc, id interface{}, job floc.Job, timeoutTrigger TimeoutTrigger) floc.Job

OnTimeout protects the job from taking too much time on execution. In addition it takes TimeoutTrigger func which called if time is out. The job is run in it's own goroutine while the current goroutine waits until the job finished or time went out or the flow is finished.

func Panic

func Panic(job floc.Job) floc.Job

Panic protects the job from falling into panic. On panic the flow will be canceled with the ErrPanic result. Guarding the job from falling into panic is effective only if the job runs in the current goroutine.

func Resume

func Resume(mask floc.ResultMask, job floc.Job) floc.Job

Resume resumes execution of the flow possibly finished by the job. If the mask is empty execution will be resumed regardless the reason it was finished. Otherwise execution will be resumed if the reason it finished with is masked.

func Timeout

func Timeout(when WhenTimeoutFunc, id interface{}, job floc.Job) floc.Job

Timeout protects the job from taking too much time on execution. The job is run in it's own goroutine while the current goroutine waits until the job finished or time went out or the flow is finished.

Types

type PanicTrigger

type PanicTrigger func(ctx floc.Context, ctrl floc.Control, v interface{})

PanicTrigger is triggered when the goroutine state is recovered after panic.

type TimeoutTrigger

type TimeoutTrigger func(ctx floc.Context, ctrl floc.Control, id interface{})

TimeoutTrigger triggers when the execution of the job timed out.

type WhenDeadlineFunc

type WhenDeadlineFunc func(ctx floc.Context, id interface{}) time.Time

WhenDeadlineFunc calculates the exact deadline passed in Deadline guards. The implementation may use the state and the id for accurate calculation of the deadline.

func ConstDeadline

func ConstDeadline(deadline time.Time) WhenDeadlineFunc

ConstDeadline returns constant deadline.

func DeadlineIn

func DeadlineIn(delay time.Duration) WhenDeadlineFunc

DeadlineIn calculates the deadline in the future with constant delay from now.

type WhenTimeoutFunc

type WhenTimeoutFunc func(ctx floc.Context, id interface{}) time.Duration

WhenTimeoutFunc calculates the exact timeout passed in Timeout guards. The implementation may use the state and the id for accurate calculation of the timeout.

func ConstTimeout

func ConstTimeout(timeout time.Duration) WhenTimeoutFunc

ConstTimeout returns constant timeout.

Jump to

Keyboard shortcuts

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