task

package
v3.31.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBackoffResetDuration = time.Minute
	DefaultBackoffJitter        = 0.1
)

Values for DefaultBackoffConfig.

Variables

View Source
var (
	// DefaultBackoffIntervals are the default task backoff intervals.
	DefaultBackoffIntervals = [...]time.Duration{
		10 * time.Millisecond,
		50 * time.Millisecond,
		100 * time.Millisecond,
		time.Second,
	}
	// DefaultBackoffIntervalFunc is the default BackoffIntervalFunc.
	DefaultBackoffIntervalFunc = MakeBackoffIntervalFunc(false, DefaultBackoffResetDuration, DefaultBackoffIntervals[:]...)
	// DefaultBackoffConfig is the default task backoff config.
	DefaultBackoffConfig = &BackoffConfig{
		Jitter:       DefaultBackoffJitter,
		IntervalFunc: DefaultBackoffIntervalFunc,
	}

	// DialBackoffIntervals are the default task backoff intervals for tasks using Dial.
	DialBackoffIntervals = [...]time.Duration{
		100 * time.Millisecond,
		time.Second,
		10 * time.Second,
	}
	// DialBackoffIntervalFunc is the default BackoffIntervalFunc for tasks using Dial.
	DialBackoffIntervalFunc = MakeBackoffIntervalFunc(false, DefaultBackoffResetDuration, DialBackoffIntervals[:]...)
	// DialBackoffConfig is the default task backoff config for tasks using Dial.
	DialBackoffConfig = &BackoffConfig{
		Jitter:       DefaultBackoffJitter,
		IntervalFunc: DialBackoffIntervalFunc,
	}
)

Functions

func DefaultStartTask

func DefaultStartTask(conf *Config)

DefaultStartTask is the default TaskStarter.

Types

type BackoffConfig

type BackoffConfig struct {
	Jitter       float64
	IntervalFunc BackoffIntervalFunc
}

BackoffConfig represents task backoff configuration.

type BackoffIntervalFunc

type BackoffIntervalFunc func(ctx context.Context, executionDuration time.Duration, invocation uint, err error) time.Duration

BackoffIntervalFunc is a function that decides the backoff interval based on the attempt history. invocation is a counter, which starts at 1 and is incremented after each task function invocation.

func MakeBackoffIntervalFunc

func MakeBackoffIntervalFunc(onFailure bool, resetDuration time.Duration, intervals ...time.Duration) BackoffIntervalFunc

MakeBackoffIntervalFunc returns a new BackoffIntervalFunc.

type Config

type Config struct {
	Context context.Context
	ID      string
	Func    Func
	Done    func()
	Restart Restart
	Backoff *BackoffConfig
}

Config represents task configuration.

type Func

type Func func(context.Context) error

Func is the task function.

func (Func) Execute

func (f Func) Execute(ctx context.Context, logger log.Interface) (err error)

Execute executes the task function.

type Restart

type Restart uint8

Restart defines a task's restart policy.

const (
	// RestartNever denotes a restart policy that never restarts tasks after success or failure.
	RestartNever Restart = iota
	// RestartAlways denotes a restart policy that always restarts tasks, on success and failure.
	RestartAlways
	// RestartOnFailure denotes a restart policy that restarts tasks on failure.
	RestartOnFailure
)

type StartTaskFunc

type StartTaskFunc func(*Config)

StartTaskFunc is a function that implements the TaskStarter interface.

func (StartTaskFunc) StartTask

func (f StartTaskFunc) StartTask(conf *Config)

StartTask implements the TaskStarter interface.

type Starter

type Starter interface {
	// StartTask starts the specified task function, optionally with restart policy and backoff.
	StartTask(*Config)
}

Starter starts tasks with a TaskConfig.

Jump to

Keyboard shortcuts

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