scheduler

package
v0.0.0-...-05f333e Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package scheduler maintains scheduler utility for scheduling arbitrary jobs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScheduleJobs

func ScheduleJobs(ctx context.Context, jobs []Job, synchronous bool)

ScheduleJobs schedules required jobs and waits for it to finish if synchronous is true.

Types

type Job

type Job interface {
	// ID returns the job id.
	ID() string
	// Interval returns the interval at which job should be rescheduled and
	// a bool determining if job should be scheduled starting now.
	// If false, first run will be at time now+interval.
	Interval() (time.Duration, bool)
	// ShouldEnable specifies if the job should be enabled for scheduling.
	ShouldEnable(context.Context) bool
	// Run triggers the job for single execution. It returns error if any
	// and a bool stating if scheduler should continue or stop scheduling.
	Run(context.Context) (bool, error)
}

Job defines the interface between the schedule manager and the actual job.

type Scheduler

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

Scheduler implements job schedule manager and offers a way to schedule/unschedule new jobs.

func Get

func Get() *Scheduler

Get starts and returns scheduler instance.

func (*Scheduler) ScheduleJob

func (s *Scheduler) ScheduleJob(ctx context.Context, job Job, synchronous bool) error

ScheduleJob adds a job to schedule at defined interval.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops executing new jobs.

func (*Scheduler) UnscheduleJob

func (s *Scheduler) UnscheduleJob(jobID string)

UnscheduleJob removes the job from schedule.

Jump to

Keyboard shortcuts

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