scheduler

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

README

Scheduler library

Allows the application to run background jobs.

Install

To install the library

$ go get github.com/najibulloShapoatov/server-core/scheduler

Usage example

task := Task{
	Name:     "task 1",
	Spec:     "* * * * * *",
	MaxRetry: 3,
	Job: func() (err error) {
	    // Do something
	    return err
	},
}
err := RegisterJob(&task)

if err != nil {
    UnregisterJob(&task)
}

###Cron Expression Format

Field name   | Mandatory? | Allowed values  | Allowed special characters
----------   | ---------- | --------------  | --------------------------
Seconds      | Yes        | 0-59            | * / , -
Minutes      | Yes        | 0-59            | * / , -
Hours        | Yes        | 0-23            | * / , -
Day of month | Yes        | 1-31            | * / , - ?
Month        | Yes        | 1-12 or JAN-DEC | * / , -
Day of week  | Yes        | 0-6 or SUN-SAT  | * / , - ?

* : every
, : multiple values
- : ranges
? : can be used for leaving Day Of month or Day of week blank

###Predefined schedules

Entry                  | Description                                | Equivalent To
-----                  | -----------                                | -------------
@yearly (or @annually) | Run once a year, midnight, Jan. 1st        | 0 0 0 1 1 *
@monthly               | Run once a month, midnight, first of month | 0 0 0 1 * *
@weekly                | Run once a week, midnight between Sat/Sun  | 0 0 0 * * 0
@daily (or @midnight)  | Run once a day, midnight                   | 0 0 0 * * *
@hourly                | Run once an hour, beginning of hour        | 0 0 * * * *
@every <duration>      | Run every time specified, eg: @every 1h30m |

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterJob

func RegisterJob(task *Task) error

RegisterJob registers a new job

func UnregisterJob

func UnregisterJob(task *Task) error

UnregisterJob unregisters a job

Types

type ScheduleFunc

type ScheduleFunc func() error

type Task

type Task struct {
	Name     string
	Spec     string
	MaxRetry int
	Job      ScheduleFunc
	Cluster  *cluster.Cluster
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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