executor

package
v0.0.0-...-9c428b3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJobNotFound                  = errors.New("job not found")
	ErrTooLate                      = errors.New("too late")
	ErrNotWithinExecutorGracePeriod = errors.New("job is not within executor grace period")
)
View Source
var (
	ErrExecutorIsClosed = errors.New("executor is closed")
)

Functions

func NewExecutor

func NewExecutor(jobCh chan<- *jobmodels.Job, gracePeriod time.Duration, accuracy time.Duration) *executorImpl

NewExecutor creates a new executor that will start dispatching jobs when the trigger time of the job is reached.

Refer executorImpl for more details.

func NewJobHeap

func NewJobHeap() *jobHeap

Types

type Executor

type Executor interface {

	// Queue adds the job to the execution queue.
	// When the job is ready to be executed, it will be sent to the job channel.
	Queue(job jobmodels.Job) error

	// Delete deletes the queued job.
	// If the job is not queued, it will return ErrJobNotFound
	Delete(jobID string) error

	// returns the job with the given jobID.
	GetJob(jobId string) (job *jobmodels.Job, version int, deleted bool, err error)

	// Close closes the executor and waits for all the jobs to finish executing.
	Close()
}

Executor queues the jobs and runs them one by one. It also includes methods to delete or update the job so that you can change the job state when it is queued in the memory.

type JobQueue

type JobQueue interface {
	AddJob(entry *jobEntry)
	NextJob() *jobEntry
	Len() int
}

Jump to

Keyboard shortcuts

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