Documentation ¶
Index ¶
- func Retry(timeout time.Duration, max int) func(FuncJob) FuncJob
- type Chain
- type CronJob
- func (c *CronJob) AddFunc(cmd FuncJob, schedule Schedule, confs ...JobConf) int
- func (c *CronJob) Jobs() []*Node
- func (c *CronJob) Location() *time.Location
- func (c *CronJob) Now() time.Time
- func (c *CronJob) RemoveJob(id int)
- func (c *CronJob) Run()
- func (c *CronJob) Start()
- func (c *CronJob) Stop()
- func (c *CronJob) StopWithFlush() context.Context
- type CronJobConf
- type CyclicSchedule
- type FuncJob
- type Job
- type JobConf
- type Node
- type Schedule
- type Scheduler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Chain ¶
Chain is a slice of decorator functions.
func MergeChains ¶
MergeChains merges n (field) chains into 1 parent chain.
type CronJob ¶
type CronJob struct {
// contains filtered or unexported fields
}
func New ¶
func New(confs ...CronJobConf) *CronJob
func (*CronJob) AddFunc ¶
AddFunc adds the function: cmd (field) to the execution cycle.
can be called after starting the execution cycle or before.
(*CronJob).AddFunc(foo, cronjob.In(time.Now(), 4 * time.Hour))
will schedule foo to run in 4 hours from time.Now()
func (*CronJob) RemoveJob ¶
RemoveJob removes the job with id: id (field). (no-op if job not found)
can be called after starting the execution cycle or before.
func (*CronJob) Run ¶
func (c *CronJob) Run()
Start the processing thread.
no-op if already running.
func (*CronJob) Start ¶
func (c *CronJob) Start()
Start the processing thread in its own gorutine.
no-op if already running.
func (*CronJob) Stop ¶
func (c *CronJob) Stop()
Stop stops the cronjobs processing thread.
no-op if not running.
func (*CronJob) StopWithFlush ¶
StopWithFlush stops the cronjobs processing thread.
runs all the current jobs and cleans the scheduler.
no-op if not running.
type CronJobConf ¶
type CronJobConf func(*CronJob)
CronJobConf represents a function to configure the behaviour of cronjob.
func WithLocation ¶
func WithLocation(loc *time.Location) CronJobConf
WithLocation sets the location used by cronjob.
func WithLogger ¶
func WithLogger(logger *log.Logger) CronJobConf
WithLogger overwrites the default logger.
type CyclicSchedule ¶
type JobConf ¶
type JobConf func(*Job)
JobConf represents a function to configure the behaviour of a job.
func WithRunOnStart ¶
func WithRunOnStart() JobConf
WithRunOnStart makes the job run on start.
if running: run when added.
if not running: run when cronjob starts.
note: the job will run with any previous configuration provided.
type Node ¶
type Node struct { // The id of the node in the storage system. Id int // The schedule the node is set to be activated on. Schedule Schedule // The job which needs to be ran. Job *Job // contains filtered or unexported fields }
Node represents a node in the storage system.
type Schedule ¶
type Schedule interface { // Calculate calculates the duartion till the next activation time. Calculate(time.Time) time.Duration }
func EveryFixed ¶
EveryFixed finds the next time interval: every (field) and runs it at the nearest interval.
example:
cronjob.EveryFixed(time.Hour * 3)
the schedule will find the next 3 hour interval to run at.
possible 3 hour intervals: 03:00, 06:00, 09:00, 12:00, 15:00, 18:00, 21:00, 24:00
type Scheduler ¶
type Scheduler interface { // NextCycle returns the duration to sleep before next activation cycle. NextCycle(time.Time) time.Duration // RunNow returns the jobs that need to be ran now and cleans the scheduler. RunNow(time.Time) []*Node // GetAll returns all the nodes in the scheduler. GetAll() []*Node // AddNode adds a new node to the scheduler. AddNode(time.Time, *Node) // RemoveNode removes node with id provided. RemoveNode(int) // Clean removes the node (field) and re-calculates appropriate nodes. Clean(time.Time, []*Node) }