usched

package
v0.0.0-...-cc23fee Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanJob

type ChanJob struct {
	Name   string        // name of job (will be sent in StartC)
	StartC chan *ChanJob // chan scheduler uses to notify job should start
	StopC  chan struct{} // chan job uses to notify that it is done

	CloseStart bool // true if we Close StartC
	CloseStop  bool // true if we Close StopC
	// contains filtered or unexported fields
}

Adapt Schedulable to provide notifications to a chan

func (*ChanJob) Close

func (this *ChanJob) Close()

Notify we should no longer be invoked

func (*ChanJob) Done

func (this *ChanJob) Done()

Notify done doing work for this invocation

func (*ChanJob) OnSchedule

func (this *ChanJob) OnSchedule()

Invoked by Scheduler to run this periodically

implement Schedulable

func (*ChanJob) Schedule

func (this *ChanJob) Schedule(s *Scheduler, interval string) (err error)

Schedule this with the Scheduler

You may specify your own chan(s) ahead of time

type Schedulable

type Schedulable interface {
	OnSchedule()
}

implement this with whatever you want scheduler to run

type SchedulableFunc

type SchedulableFunc func()

a func that is schedulable

func (SchedulableFunc) OnSchedule

func (this SchedulableFunc) OnSchedule()

type Scheduler

type Scheduler struct {
	Min  time.Duration // minimum interval allowed
	Max  time.Duration // maximum interval allowed
	Init int           // max allowed concurrent initializations, or -1
	// contains filtered or unexported fields
}

Use this to schedule jobs

Manages job scheduling so that each job is unique by name.

Prevents each job from running at the same time as itself.

Prevents scheduling intervals that are too long or too short

Randomizes interval to spread out the load.

Performs early initialization of jobs, as directed.

func NewScheduler

func NewScheduler() (rv *Scheduler)

Create a Scheduler

func (*Scheduler) Add

func (this *Scheduler) Add(name, interval string, s Schedulable) (err error)

Schedule or reschedule a job

func (*Scheduler) AddFunc

func (this *Scheduler) AddFunc(name, interval string, f func()) (err error)

Schedule or reschedule a func as a job

func (*Scheduler) LockJob

func (this *Scheduler) LockJob(name string) (locked bool)

prevent the scheduler from running the job, returning true if exclusive access was achieved

func (*Scheduler) Remove

func (this *Scheduler) Remove(name string)

Cancel a job

Note: if you Remove, then Add the same named job, you might run the risk of running the same job concurrently. It is better in that case to just use Add.

func (*Scheduler) RunJobAsync

func (this *Scheduler) RunJobAsync(name string)

start the job right now in its own goroutine

func (*Scheduler) RunJobSync

func (this *Scheduler) RunJobSync(name string)

run the job right now in the current goroutine

func (*Scheduler) Start

func (this *Scheduler) Start() (self *Scheduler)

Start the Scheduler

func (*Scheduler) Stop

func (this *Scheduler) Stop()

Stop the scheduler

func (*Scheduler) UnlockJob

func (this *Scheduler) UnlockJob(name string)

allow the scheduler to run the job

func (*Scheduler) ValidInterval

func (this *Scheduler) ValidInterval(in string) (err error)

validate and randomize interval

Jump to

Keyboard shortcuts

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