scheduler

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Stop time.Duration = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type ScheduleOption

type ScheduleOption func(*Task)

ScheduleOption is a function configuring a task.

func NextAfterDuration

func NextAfterDuration(d time.Duration) ScheduleOption

NextAfterDuration configures the task to only run after the given amount of wall time.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func New

func New() *Scheduler

New creates a new scheduler instance. The slot count defaults to the number CPUs in the system.

func (*Scheduler) Add

func (s *Scheduler) Add(fn TaskFunc, opts ...ScheduleOption)

Add a new task function to the scheduler. Unless configured otherwise through an option tasks are started in the order they're added.

func (*Scheduler) Quiesce

func (s *Scheduler) Quiesce(ctx context.Context) error

Quiesce waits until all tasks have been run or the context is cancelled. Tasks are not affected on context cancellation. If tasks are added concurrently the behaviour is unspecified.

func (*Scheduler) SetSlots

func (s *Scheduler) SetSlots(count int)

SetSlots changes the number of tasks running concurrently.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start launches the scheduler loop in a separate goroutine before returning. Tasks already in the queue will be run in the same order as they would be if they were added later.

func (*Scheduler) Stop

func (s *Scheduler) Stop(ctx context.Context) error

Stop waits until currently running tasks have finished or the context is cancelled. The latter will also cancel the context for running tasks. Tasks not yet started will be abandoned.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task describes one scheduled tasks.

type TaskError

type TaskError struct {
	// Underlying error
	Err error

	// Delay before re-running the task. Use a negative value to make the error
	// permanent (i.e. don't schedule a retry).
	RetryDelay time.Duration
}

func AsTaskError

func AsTaskError(err error) *TaskError

func (*TaskError) Error

func (e *TaskError) Error() string

func (*TaskError) Permanent

func (e *TaskError) Permanent() bool

func (*TaskError) Unwrap

func (e *TaskError) Unwrap() error

type TaskFunc

type TaskFunc func(context.Context) error

TaskFunc is the signature of functions implementing tasks. They're called when it's the task's turn. Returning nil indicates success and the task is removed from the queue. *TaskError can be returned to configure a retry delay. A non-nil error of another type is always a permanent failure.

Jump to

Keyboard shortcuts

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