run

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: BSD-2-Clause Imports: 11 Imported by: 38

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

This section is empty.

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.

func SkipErrors

func SkipErrors(fn Func) func(context.Context) error

SkipErrors runs the given Func and returns always nil.

func SkipErrorsAndReport

func SkipErrorsAndReport(
	fn Func,
	hasCaptureErrorAndWait HasCaptureErrorAndWait,
	tags map[string]string,
) func(context.Context) error

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

Types

type AddFire

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

AddFire allow add a new trigger

type Backoff

type Backoff struct {
	Delay   time.Duration `json:"delay"`
	Retries int           `json:"retries"`
}

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 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

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