scheduler

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Overview

Package scheduler sends a job on a channel when it is time to run it.

The scheduler takes a Task and cron expression. At the tasks's start time, the task is sent to the run channel. This allows the control of task executon outside of the scheduler. When the task is finished, the executor calls Task.End() to tell the scheduler the task is finished.

Index

Constants

View Source
const RunNow = ""

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Context  context.Context
	End      context.CancelFunc
	ID       cron.EntryID
	RunCount int
	Task     tasks.Task
}

Job is information that is output when a job runs

type Scheduler

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

Scheduler signals when items start and stop

func New

func New() *Scheduler

New returns a new Scheduler instance

func NewWithSeconds

func NewWithSeconds() *Scheduler

Create a new scheduler that uses a non-standard cron schedule spec that contains seconds.

func (*Scheduler) Add

func (s *Scheduler) Add(cronExp string, task tasks.Task, maxRunTime, scheduleLimit time.Duration, lastRunCount int) (cron.EntryID, error)

Add adds a Task to be scheduled.

func (*Scheduler) Close

func (s *Scheduler) Close(ctx context.Context)

Close stops the scheduler and all its running jobs. The context passed to Close determines how long the scheduler waits for running jobs to complete before it cancels them. A nil context means do not wait.

func (*Scheduler) Remove

func (s *Scheduler) Remove(jobID cron.EntryID)

Remove removes a Task from the scheduler and stops it if it is running.

func (*Scheduler) RunChan

func (s *Scheduler) RunChan() <-chan Job

RunChan returns a channel that sends jobs to be run

Jump to

Keyboard shortcuts

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