jobrunner

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

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:

  1. Protection against job panics. (They print to ERROR instead of take down the process)
  2. (Optional) Limit on the number of jobs that may run simulatenously, to limit resource consumption.
  3. (Optional) Protection against multiple instances of a single job running concurrently. If one execution runs into the next, the next will be queued.
  4. Cron expressions may be defined in app.conf and are reusable across jobs.
  5. Job status reporting. [WIP]

Index

Constants

View Source
const DEFAULT_JOB_POOL_SIZE = 10
View Source
const UNNAMED = "(unnamed)"

Variables

View Source
var (
	// Singleton instance of the underlying job scheduler.
	MainCron *cron.Cron
)

Functions

func Entries

func Entries() []cron.Entry

Entries returns the detailed list of currently running recurring jobs to remove an entry, first retrieve the ID of entry

func Every

func Every(duration time.Duration, job cron.Job)

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 In

func In(duration time.Duration, job cron.Job)

Run the given job once, after the given delay.

func Now

func Now(job cron.Job)

Run the given job right now.

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 Schedule

func Schedule(spec string, job cron.Job) error

func Start

func Start(v ...int)

func StatusJSON

func StatusJSON() map[string]interface{}

func Stop

func Stop()

Stop ALL active jobs from running at the next scheduled time

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))

func (Func) Run

func (r Func) Run()

type Job

type Job struct {
	Name string

	Status  string
	Latency string
	// contains filtered or unexported fields
}

func AddJob

func AddJob(job cron.Job) *Job

func New

func New(job cron.Job) *Job

func (*Job) Run

func (j *Job) Run()

func (*Job) StatusUpdate

func (j *Job) StatusUpdate() string

type StatusData

type StatusData struct {
	ID        cron.EntryID
	JobRunner *Job
	Next      time.Time
	Prev      time.Time
}

func StatusPage

func StatusPage() []StatusData

Jump to

Keyboard shortcuts

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