Documentation ¶
Overview ¶
A job runner for executing scheduled or ad-hoc tasks asynchronously from HTTP requests.
It adds a couple of features on top of the Robfig cron package:
- Protection against job panics. (They print to ERROR instead of take down the process)
- (Optional) Limit on the number of jobs that may run simulatenously, to limit resource consumption.
- (Optional) Protection against multiple instances of a single job running concurrently. If one execution runs into the next, the next will be queued.
- Cron expressions may be defined in app.conf and are reusable across jobs.
- Job status reporting. [WIP]
Index ¶
- Constants
- Variables
- func Entries() []cron.Entry
- func Remove(id cron.EntryID)
- func Start(v ...int)
- func StatusJson() map[string]interface{}
- func Stop()
- type Func
- type Job
- func AddJob(job cron.Job) *Job
- func Every(duration time.Duration, job cron.Job, jobName string, obj []byte) *Job
- func In(duration time.Duration, job cron.Job, jobName string, obj []byte) *Job
- func New(job cron.Job, jobName string, obj []byte, spec string) *Job
- func Now(job cron.Job, jobName string, obj []byte) *Job
- func Schedule(spec string, job cron.Job, jobName string, obj []byte) (*Job, error)
- type StatusData
Constants ¶
const DefaultJobPoolSize = 10
const UNNAMED = "(unnamed)"
Variables ¶
var (
// Singleton instance of the underlying job scheduler.
MainCron *cron.Cron
)
Functions ¶
func Entries ¶
func Entries() []cron.Entry
Return detailed list of currently running recurring jobs to remove an entry, first retrieve the ID of entry
func Remove ¶
func Remove(id cron.EntryID)
Remove a specific job from running Get EntryID from the list job entries jobrunner.Entries() If job is in the middle of running, once the process is finished it will be removed
func StatusJson ¶
func StatusJson() map[string]interface{}
Types ¶
type Func ¶
type Func func()
Callers can use jobs.Func to wrap a raw func. (Copying the type to this package makes it more visible)
For example:
jobrunner.Schedule("cron.frequent", jobs.Func(myFunc))
type Job ¶
type Job struct { Name string `json:"name"` Outer []byte `json:"outer"` Status string `json:"status,omitempty"` Latency string `json:"latency,omitempty"` Spec string `json:"spec"` // contains filtered or unexported fields }
func Every ¶
Run the given job at a fixed interval. The interval provided is the time between the job ending and the job being run again. The time that the job takes to run is not included in the interval.
func (*Job) StatusUpdate ¶
type StatusData ¶
func StatusPage ¶
func StatusPage() []StatusData