bastiankoetsier / schedule

Go-based Task Scheduling System

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Go-based Task Scheduling System

License:MIT License


Languages

Language:Go 100.0%