schedule

package module
v0.0.0-...-b46cab1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2018 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Schedule

GoDoc Go Report Card cover.run go

Schedule is a small library that helps you specify recurring tasks in a cronjob-like interface (without actually using cron's syntax). It is heavily inspired by Laravel's Task Scheduling and uses cronexpr for the heavy lifting.

Install

I recommend dep for dependency management:

dep ensure -add github.com/bastiankoetsier/schedule

Usage

Example

// create a base context with cancellation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

s := &schedule.Schedule{}
// Start returns a channel which you can receive on as soon as the scheduler is shut down
shutDown := s.Start(ctx)

// You can use the helper schedule.RunFunc to wrap any arbitray function to use
s.Command(schedule.RunFunc(func(ctx context.Context) {
    fmt.Println("I run every minute", time.Now())
})).EveryMinute()

// You can also chain the specs on when to run:
s.Command(schedule.RunFunc(func(ctx context.Context) {
    fmt.Println("I run only mondays, but every fifteen minutes of that weekday", time.Now())
})).Mondays().EveryFifteenMinutes()
Matchers

The chainable matchers can be found on the Entry type.

Documentation

Overview

Package schedule is a small library that helps you specify recurring tasks in a cronjob-like interface (without actually using cron's syntax).

Index

Constants

View Source
const (
	// Sunday is representation of cron's 0 for Sundays
	Sunday = cronDay("0")
	// Monday is representation of cron's 1 for Mondays
	Monday = cronDay("1")
	// Tuesday is representation of cron's 2 for Tuesdays
	Tuesday = cronDay("2")
	// Wednesday is representation of cron's 3 for Wednesdays
	Wednesday = cronDay("3")
	// Thursday is representation of cron's 4 for Thursdays
	Thursday = cronDay("4")
	// Friday is representation of cron's 5 for Fridays
	Friday = cronDay("5")
	// Saturday is representation of cron's 6 for Saturdays
	Saturday = cronDay("6")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Command Runner
	// contains filtered or unexported fields
}

Entry is the holding type that has the crons specification for when the job has to run This is stored in the unexported field expression. Command keeps track of the actual func to run

func (*Entry) Daily

func (e *Entry) Daily() *Entry

Daily specifies that this entry should be executed at hour 0 and minute 0

func (*Entry) DailyAt

func (e *Entry) DailyAt(spec string) *Entry

DailyAt gives you more flexibility in specifying exactly at what time the Runner should be executed You need to specify the spec like "15:23". This func panics if an invalid argument is given!

func (*Entry) Days

func (e *Entry) Days(days ...cronDay) *Entry

Days specifies the days the Runner should be executed on. This follows the specification for cron jobs, meaning it goes from 0–6 or SUN–SAT

func (*Entry) EveryFifteenMinutes

func (e *Entry) EveryFifteenMinutes() *Entry

EveryFifteenMinutes specifies that this entry should be executed every fifteen minutes

func (*Entry) EveryFiveMinutes

func (e *Entry) EveryFiveMinutes() *Entry

EveryFiveMinutes specifies that this entry should be executed every five minutes

func (*Entry) EveryMinute

func (e *Entry) EveryMinute() *Entry

EveryMinute specifies that this entry should be executed every single minute

func (*Entry) EveryTenMinutes

func (e *Entry) EveryTenMinutes() *Entry

EveryTenMinutes specifies that this entry should be executed every ten minutes

func (*Entry) EveryThirtyMinutes

func (e *Entry) EveryThirtyMinutes() *Entry

EveryThirtyMinutes specifies that this entry should be executed every thirty minutes

func (*Entry) Fridays

func (e *Entry) Fridays() *Entry

Fridays runs every Friday every minute (if not specified further)

func (*Entry) Hourly

func (e *Entry) Hourly() *Entry

Hourly specifies that this entry should be executed every hour at the minute 0

func (*Entry) Mondays

func (e *Entry) Mondays() *Entry

Mondays runs every Monday every minute (if not specified further)

func (*Entry) Saturdays

func (e *Entry) Saturdays() *Entry

Saturdays runs every Saturday every minute (if not specified further)

func (*Entry) String

func (e *Entry) String() string

func (*Entry) Sundays

func (e *Entry) Sundays() *Entry

Sundays runs every Sunday every minute (if not specified further)

func (*Entry) Thursdays

func (e *Entry) Thursdays() *Entry

Thursdays runs every Thursday every minute (if not specified further)

func (*Entry) Tuesdays

func (e *Entry) Tuesdays() *Entry

Tuesdays runs every Tuesday every minute (if not specified further)

func (*Entry) Wednesdays

func (e *Entry) Wednesdays() *Entry

Wednesdays runs every Wednesday every minute (if not specified further)

func (*Entry) Weekdays

func (e *Entry) Weekdays() *Entry

Weekdays runs every MON-FRI at hour 0 and minute 0

func (*Entry) Weekly

func (e *Entry) Weekly() *Entry

Weekly runs every Friday at hour 0, minute 0 and day 5

type RunFunc

type RunFunc func(ctx context.Context)

RunFunc is a wrapper for Runner to use plain functions instead of implementing a type for Runner

func (RunFunc) Run

func (r RunFunc) Run(ctx context.Context)

Run satisfies the Runner interface

type Runner

type Runner interface {
	Run(ctx context.Context)
}

Runner is the definition of a func to run on a given schedule

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule is the main type that "stores" the jobs to execute

func (*Schedule) Command

func (s *Schedule) Command(r Runner) *Entry

Command sets a new command in the scheduler. It returns an entry which can be used to set a time schedule.

func (*Schedule) Start

func (s *Schedule) Start(ctx context.Context) <-chan struct{}

Start starts the scheduler to run. It checks every minute for "due" tasks to execute them given the same context as the scheduler runs on, to support potential graceful shutdown.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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