scheduler

package
v3.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// Precondition that needs to be satisfied before this batch will be
	// executed.
	// Can be a Time or Duration to indicate a time delay for batching.
	// Can be a chan that is satisfied when closed.
	// Can be nil for no precondition.
	Precondition interface{}

	// Key is used to batch together Tasks with the same key.
	Key interface{}

	// Priority is used to prioritize batches.
	// The larger numbers represent higher priorities.
	Priority int
}

Batch describes the batching rules for a scheduled Task.

type Executable

type Executable struct {
	Task      Task        // The work to be done.
	Cancelled task.Signal // Has this work been cancelled?
	Result    Result      // The result callback.
}

Executable holds a task and it's result.

type Executor

type Executor func(context.Context, *status.Replay, []Executable, Batch)

Executor is the executor of Executables. The executor can only work on one list of Executables at a time.

type Result

type Result func(val interface{}, err error)

Result is the result of an executed Task.

type Scheduler

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

Scheduler schedules Tasks to Executors, batching where possible.

func New

func New(ctx context.Context, device id.ID, exec Executor) *Scheduler

New returns a new Scheduler that will execute Tasks with exec.

func (*Scheduler) NumTasksQueued

func (s *Scheduler) NumTasksQueued() int

NumTasksQueued returns the number of queued tasks.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(ctx context.Context, t Task, b Batch) (val interface{}, err error)

Schedule schedules t to be executed on s. Tasks with compatible batches may be executed together.

type Task

type Task interface{}

Task represents a single unit or work.

Jump to

Keyboard shortcuts

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