schedule

package
v0.0.0-...-d772fc0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package schedule implements all the scheduling of jobs. The approach used to implement is the same as the http golang library style. We have Schedulers that will be executed (Run method). We have SchedulerFunc that is a wrap of a function to convert it to an schedule object and be able to run. like http middlewares, we create schedulers with functions that receive other schedulers as parameters and create a chain (schedule/chain)

Package schedule contains all the logic to execute the jobs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

type Cron struct {

	// Results is a blocking channel where the crons will post their results as
	// a notification event of finished (ideally the actions of a finish result should
	// be in the chain of the scheduler (see `scheduler/run`)
	Results chan *job.Result
	// contains filtered or unexported fields
}

Cron is be the registerer of jobs

func NewDummyCron

func NewDummyCron(cfg *config.AppConfig, storage storage.Client, exitStatus int, out string) *Cron

NewDummyCron creates a new instance of a cron that will execute dummy jobs (do nothing) when the time comes

func NewSimpleCron

func NewSimpleCron(cfg *config.AppConfig, storage storage.Client) *Cron

NewSimpleCron creates a new instance of a cron initialized with the basic functionality

func (*Cron) RegisterCronJob

func (c *Cron) RegisterCronJob(j *job.Job)

RegisterCronJob registers a cron to be run when its it's time

func (*Cron) Start

func (c *Cron) Start(f func(*job.Result)) error

Start starts cron job scheduler starts the result listener. loads stored jobs from database if DontScheduleJobsStart option is disabled f parameter is the function that will be executed for each result, could be nil.

func (*Cron) Stop

func (c *Cron) Stop() error

Stop stops cron job scheduler and result listener

type Scheduler

type Scheduler interface {
	Run(*job.Result, *job.Job)
}

Scheduler implements the unit of execution of a job, it mus implement run method this method will be the one that will execute job logic

func DummyRun

func DummyRun(exitStatus int, result string) Scheduler

DummyRun has a dummy chain for tests

func DummyScheduler

func DummyScheduler(exitStatus int, resultOut string, s Scheduler) Scheduler

DummyScheduler breaks the schedule chain and returns an specific result

func HTTPScheduler

func HTTPScheduler(timeout time.Duration, s Scheduler) Scheduler

HTTPScheduler makes an http call to the job destination and registers the result http executed jobs should return 200 if job went ok and 500 if it went wrong, everything else will be interpreted as unknown

func LogScheduler

func LogScheduler(s Scheduler) Scheduler

LogScheduler logs the execution of a job

func SimpleRun

func SimpleRun() Scheduler

SimpleRun has the simples execution flow of a job, log, time, and http

func TimingScheduler

func TimingScheduler(s Scheduler) Scheduler

TimingScheduler registers the start and finish time of a job

type SchedulerFunc

type SchedulerFunc func(*job.Result, *job.Job)

SchedulerFunc is a handy scheduler that runs the function itself

func (SchedulerFunc) Run

func (s SchedulerFunc) Run(r *job.Result, j *job.Job)

Run implements the start of the execution

Jump to

Keyboard shortcuts

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