Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

bastiankoetsier/schedule

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages