run

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: BSD-2-Clause Imports: 11 Imported by: 26

README

Run

This repo contains helps for running go functions mostly in parallel with different behaviour on errors.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWaiter = NewWaiter()

Functions

func All

func All(ctx context.Context, funcs ...Func) error

All executes all given functions. Errors are wrapped into one aggregate error.

func CancelOnFirstError

func CancelOnFirstError(ctx context.Context, funcs ...Func) error

CancelOnFirstError executes all given functions. When a function encounters an error all remaining functions will be canceled.

func CancelOnFirstErrorWait

func CancelOnFirstErrorWait(ctx context.Context, funcs ...Func) error

CancelOnFirstErrorWait executes all given functions. When a function encounters an error all remaining functions will be canceled.

func CancelOnFirstFinish

func CancelOnFirstFinish(ctx context.Context, funcs ...Func) error

CancelOnFirstFinish executes all given functions. After the first function finishes, any remaining functions will be canceled.

func CancelOnFirstFinishWait

func CancelOnFirstFinishWait(ctx context.Context, funcs ...Func) error

CancelOnFirstFinishWait executes all given functions. After the first function finishes, any remaining functions will be canceled.

func NewErrorList

func NewErrorList(errs ...error) error

NewErrorList create a ErrorList with the given errors.

func NewErrorListByChan

func NewErrorListByChan(ch <-chan error) error

NewErrorListByChan create a ErrorList with the given error channel.

func NewMetrics

func NewMetrics(
	registerer prometheus.Registerer,
	namespace string,
	subsystem string,
	fn Func,
) func(ctx context.Context) error

NewMetrics create prometheus metrics for the given Func.

func Run

func Run(ctx context.Context, funcs ...Func) <-chan error

Run all functions and send each result to the returned channel.

func Sequential

func Sequential(ctx context.Context, funcs ...Func) (err error)

Sequential run every given function.

Types

type AddFire

type AddFire interface {
	// Add returns a new fire for trigger
	Add() Fire
}

AddFire allow add a new trigger

type BackgroundRunner added in v1.4.0

type BackgroundRunner interface {
	Run(runFunc Func) error
}

func NewBackgroundRunner added in v1.4.0

func NewBackgroundRunner(ctx context.Context) BackgroundRunner

type Backoff

type Backoff struct {
	// Initial delay to wait on retry
	Delay time.Duration `json:"delay"`
	// Factor initial delay is multipled on retries
	Factor float64 `json:"factor"`
	// Retries how often to retry
	Retries int `json:"retries"`
	// IsRetryAble allow the check if error is retryable
	IsRetryAble func(error) bool `json:"-"`
}

Backoff settings for retry

type ConcurrentRunner

type ConcurrentRunner interface {
	Add(ctx context.Context, fn Func)
	Run(ctx context.Context) error
	io.Closer
}

ConcurrentRunner allow run N tasks concurrent

func NewConcurrentRunner

func NewConcurrentRunner(maxConcurrent int) ConcurrentRunner

NewConcurrentRunner returns ConcurrentRunner with the given concurrent limit

type Done

type Done interface {
	// Done chan gets a element if trigger was fired
	Done() <-chan struct{}
}

Done check for a trigger

type Fire

type Fire interface {
	// Fire trigger als Dons ch to get a element
	Fire()
}

Fire a trigger

type Func

type Func func(context.Context) error

Func interface for all run utils.

func CatchPanic

func CatchPanic(fn Func) Func

CatchPanic catchs all panics for the given func

func Delayed

func Delayed(fn Func, duration time.Duration) Func

Delayed wraps the given function that delays the execution.

func LogErrors

func LogErrors(fn Func) Func

LogErrors for the given func

func Retry

func Retry(backoff Backoff, fn Func) Func

Retry on error n times and wait between the given delay.

func RetryWaiter added in v1.5.0

func RetryWaiter(backoff Backoff, waiter Waiter, fn Func) Func

RetryWaiter allow use of custom Waiter

func SkipErrors

func SkipErrors(fn Func) Func

SkipErrors runs the given Func and returns always nil.

func SkipErrorsAndReport

func SkipErrorsAndReport(
	fn Func,
	hasCaptureErrorAndWait HasCaptureErrorAndWait,
	tags map[string]string,
) Func

SkipErrorsAndReport runs the given Func, report errors to sentry and returns always nil.

func Triggered

func Triggered(fn Func, trigger <-chan struct{}) Func

Triggered calls the given fn if something arrives on chan

func (Func) Run

func (r Func) Run(ctx context.Context) error

Run the func

type HasCaptureErrorAndWait

type HasCaptureErrorAndWait interface {
	CaptureErrorAndWait(err error, tags map[string]string, interfaces ...raven.Interface) string
}

HasCaptureErrorAndWait is compatibel with sentry.Client

type MultiTrigger

type MultiTrigger interface {
	Done
	AddFire
}

MultiTrigger combines Done and AddFire

func NewMultiTrigger

func NewMultiTrigger() MultiTrigger

NewMultiTrigger returns a MultiTrigger

type ParallelSkipper

type ParallelSkipper interface {
	SkipParallel(action Func) Func
}

ParallelSkipper prevent execution of the given function at the same time.

func NewParallelSkipper

func NewParallelSkipper() ParallelSkipper

NewParallelSkipper return a new instance of ParallelSkipper.

type Runnable

type Runnable interface {
	Run(ctx context.Context) error
}

Runnable interface

type Trigger

type Trigger interface {
	Fire
	Done
}

Trigger combines fire and done

func NewTrigger

func NewTrigger() Trigger

NewTrigger create a new Trigger

type Waiter added in v1.5.0

type Waiter interface {
	Wait(ctx context.Context, wait time.Duration) error
}

func NewWaiter added in v1.5.0

func NewWaiter() Waiter

type WaiterFunc added in v1.5.0

type WaiterFunc func(ctx context.Context, wait time.Duration) error

func (WaiterFunc) Wait added in v1.5.0

func (w WaiterFunc) Wait(ctx context.Context, wait time.Duration) error

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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