tasker

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoNameSpecified = errs.Error("no name specified")
	ErrDurationLTEZero = errs.Error("duration less than or equal to zero")
	ErrNotFound        = errs.Error("task not found")
)
View Source
var TASKER_CONTEXT_KEY = contextKey{}

Functions

This section is empty.

Types

type Task

type Task struct {
	Name      string
	Func      func(ctx context.Context) error
	OnError   func(error)
	Duration  time.Duration
	OnDequeue func(ctx context.Context) error
}

Public facing task structure.

This can be used to configure the task to run.

type Tasker

type Tasker interface {
	// Enqueue a task periodically by name.
	// If there is an error, it will be of type:
	// - ErrNoNameSpecified
	// - ErrDurationLTEZero
	Enqueue(task Task) error

	// Execute a task after the duration has passed, or immediately if the duration is 0.
	// If duration is zero, the task will be executed immediately in a goroutine, but the function will return ErrDurationLTEZero.
	// If the task name is provided, the task will be reset to the new duration.
	// If the task name is not provided, the task will be executed once after the duration has passed.
	After(task Task) error

	// Dequeue a task by name.
	// If there is an error, it will be of types:
	// - ErrNoNameSpecified
	// - ErrNotFound
	Dequeue(taskName string) error
}

Tasker interface.

func New

func New() Tasker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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