A Golang job scheduling library that lets you run Go functions at pre-determined intervals using cron expressions, fixed durations, daily, weekly, monthly, or one-time schedules with support for distributed deployments.
Quick reference for core types and interfaces.
type Scheduler interface {
Start()
Shutdown() error
NewJob(JobDefinition, Task, ...JobOption) (Job, error)
Update(uuid.UUID, JobDefinition, Task, ...JobOption) (Job, error)
RemoveJob(uuid.UUID) error
RemoveByTags(...string) error
Jobs() []Job
JobsWaitingInQueue() int
}See Scheduler API
type Job interface {
ID() uuid.UUID
Name() string
Tags() []string
NextRun() (time.Time, error)
LastRun() (time.Time, error)
RunNow() error
}type Task interface {
// Internal interface
}
// Create with:
task := gocron.NewTask(func() {
// work
})See Tasks API
type LimitMode int
const (
LimitModeReschedule LimitMode = 1
LimitModeWait LimitMode = 2
)gocron.DurationJob(5*time.Minute)
gocron.DurationRandomJob(time.Minute, 5*time.Minute)gocron.CronJob("*/5 * * * *", false)
gocron.CronJob("TZ=America/New_York 0 9 * * *", false)See Cron Jobs API
gocron.DailyJob(1, gocron.NewAtTimes(gocron.NewAtTime(9, 0, 0)))
gocron.WeeklyJob(1, gocron.NewWeekdays(time.Monday), gocron.NewAtTimes(...))
gocron.MonthlyJob(1, gocron.NewDaysOfTheMonth(1, 15), gocron.NewAtTimes(...))gocron.OneTimeJob(
gocron.OneTimeJobStartDateTime(time.Now().Add(time.Hour)),
)type Logger interface {
Debug(msg string, args ...any)
Error(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
}type Monitor interface {
RecordJobTiming(
start time.Time,
duration time.Duration,
jobID uuid.UUID,
jobName string,
tags []string,
)
}type SchedulerMonitor interface {
JobScheduled(jobID uuid.UUID, job Job)
JobUnscheduled(jobID uuid.UUID, job Job)
JobStarted(jobID uuid.UUID, job Job)
JobCompleted(jobID uuid.UUID, job Job, err error)
ConcurrencyLimitReached(limitType string, job Job)
}type Elector interface {
IsLeader(context.Context) error
}type Locker interface {
Lock(context.Context, string) (Lock, error)
}
type Lock interface {
Unlock(context.Context) error
}Install with Tessl CLI
npx tessl i tessl/golang-github-com-go-co-op-gocron-v2docs
api
examples
guides