job

package
v1.11.10-rc.4 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package job provides a Scheduler to manage and execute Jobs with dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job[T any] interface {
	Execute(ctx context.Context, fulfilled []T, abandoned []T) error
}

Job is a unit of work that can be executed based on the result of resolving requested dependencies.

type Scheduler

type Scheduler[T comparable] struct {
	// contains filtered or unexported fields
}

Scheduler implements a dependency graph for jobs. Jobs can be registered with dependencies, and once all dependencies are resolved, the job will be executed.

func NewScheduler

func NewScheduler[T comparable]() *Scheduler[T]

func (*Scheduler[T]) Abandon

func (s *Scheduler[T]) Abandon(ctx context.Context, dependency T) error

Abandon a dependency. If all dependencies for a job are resolved, the job will be executed.

It is safe to call the scheduler during the execution of a job.

func (*Scheduler[T]) Fulfill

func (s *Scheduler[T]) Fulfill(ctx context.Context, dependency T) error

Fulfill a dependency. If all dependencies for a job are resolved, the job will be executed.

It is safe to call the scheduler during the execution of a job.

func (*Scheduler[_]) NumDependencies

func (s *Scheduler[_]) NumDependencies() int

NumDependencies returns the number of dependencies that jobs are currently blocking on.

func (*Scheduler[T]) Schedule

func (s *Scheduler[T]) Schedule(ctx context.Context, userJob Job[T], dependencies ...T) error

Schedule a job to be executed once all of its dependencies are resolved. If a job is scheduled with no dependencies, it's executed immediately.

In order to prevent a memory leak, all dependencies must eventually either be fulfilled or abandoned.

While registering a job with duplicate dependencies is discouraged, it is allowed.

Jump to

Keyboard shortcuts

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