go-quartz is a free, open source orchestration & scheduling project written in Go and released under MIT. It has 2,012 GitHub stars, 99 forks and 4 open issues, and was last pushed 8 months ago. On this registry it ranks #47 of 64 tracked projects in Orchestration & Scheduling, with 5 head-to-head comparisons available.

What is go-quartz?

What it is

go-quartz is a minimalist and zero-dependency scheduling library for the Go ecosystem. It is inspired by the design of the Quartz Java scheduler, and it provides a Go API for scheduling jobs with triggers. The package exposes a Scheduler interface, a Trigger interface, and a Job interface, so a Go application can define executable tasks and control when they run.

The concrete problem it solves is in-process job scheduling inside Go applications. Instead of relying on an external cron daemon or a separate scheduling service, a program can use go-quartz to start a scheduler, schedule jobs, pause, resume, delete, clear, wait, and stop them. The cron trigger supports the Quartz cron expression format and can also be used independently to calculate a future time from a previous execution time.

Key capabilities

  • The Scheduler interface supports Start, IsStarted, ScheduleJob, GetJobKeys, GetScheduledJob, DeleteJob, PauseJob, ResumeJob, Clear, Wait, and Stop.
  • StdScheduler is the implemented scheduler listed in the README.
  • CronTrigger, SimpleTrigger, and RunOnceTrigger are implemented trigger types.
  • The cron trigger fully supports the Quartz cron expression format, including seconds, minutes, hours, day of month, month, day of week, and optional year fields.
  • The cron trigger can be used independently to calculate a next fire time given a previous execution time.
  • Any Go type that implements the Job interface can be scheduled, and the job package contains several common Job implementations.

Who uses it and how

  • Go applications can use it to manage scheduled jobs inside the process with triggers.
  • Developers can schedule tasks with CronTrigger, SimpleTrigger, or RunOnceTrigger, and any type that implements the Job interface can be scheduled.
  • Operators can control the StdScheduler lifecycle with Start, Stop, Wait, and IsStarted.
  • Users can manage scheduled jobs by listing job keys, retrieving a job, pausing, resuming, deleting, or clearing jobs.
  • Teams that need multiple scheduler instances can consult the README guidance for distributed mode.

Getting started

The README identifies the Go package documentation at https://pkg.go.dev/github.com/reugn/go-quartz/quartz. The provided facts do not list a Docker image, hosted option, or other install command.

When to use it — and when not to

Use go-quartz when a Go application needs an in-process scheduler with Quartz-inspired cron semantics and zero external dependencies. Avoid it when you need a hosted scheduler, a documented persistence backend, or built-in multi-instance coordination, because the facts describe a Go library, StdScheduler, and distributed-mode guidance, not a managed service.

project readme (upstream, from github) — read inline

go-quartz

Build PkgGoDev Go Report Card codecov

A minimalistic and zero-dependency scheduling library for Go.

About

The implementation is inspired by the design of the Quartz Java scheduler.

The core scheduler component can be used to manage scheduled jobs (tasks) using triggers. The implementation of the cron trigger fully supports the Quartz cron expression format and can be used independently to calculate a future time given the previous execution time.

If you need to run multiple instances of the scheduler, see the distributed mode section for guidance.

Library building blocks

Scheduler interface
type Scheduler interface {
	// Start starts the scheduler. The scheduler will run until
	// the Stop method is called or the context is canceled. Use
	// the Wait method to block until all running jobs have completed.
	Start(context.Context)

	// IsStarted determines whether the scheduler has been started.
	IsStarted() bool

	// ScheduleJob schedules a job using the provided Trigger.
	ScheduleJob(jobDetail *JobDetail, trigger Trigger) error

	// GetJobKeys returns the keys of scheduled jobs.
	// For a job key to be returned, the job must satisfy all of the
	// matchers specified.
	// Given no matchers, it returns the keys of all scheduled jobs.
	GetJobKeys(...Matcher[ScheduledJob]) ([]*JobKey, error)

	// GetScheduledJob returns the scheduled job with the specified key.
	GetScheduledJob(jobKey *JobKey) (ScheduledJob, error)

	// DeleteJob removes the job with the specified key from the
	// scheduler's execution queue.
	DeleteJob(jobKey *JobKey) error

	// PauseJob suspends the job with the specified key from being
	// executed by the scheduler.
	PauseJob(jobKey *JobKey) error

	// ResumeJob restarts the suspended job with the specified key.
	ResumeJob(jobKey *JobKey) error

	// Clear removes all of the scheduled jobs.
	Clear() error

	// Wait blocks until the scheduler stops running and all jobs
	// have returned. Wait will return when the context passed to
	// it has expired. Until the context passed to start is
	// cancelled or Stop is called directly.
	Wait(context.Context)

	// Stop shutdowns the scheduler.
	Stop()
}

Implemented Schedulers

  • StdScheduler
Trigger interface
type Trigger interface {
	// NextFireTime returns the next time at which the Trigger is scheduled to fire.
	NextFireTime(prev int64) (int64, error)

	// Description returns the description of the Trigger.
	Description() string
}

Implemented Triggers

  • CronTrigger
  • SimpleTrigger
  • RunOnceTrigger
Job interface

Any type that implements it can be scheduled.

type Job interface {
	// Execute is called by a Scheduler when the Trigger associated with this job fires.
	Execute(context.Context) error

	// Description returns the description of the Job.
	Description() string
}

Several common Job implementations can be found in the job package.

Cron expression format

Field Name Mandatory Allowed Values Allowed Special Characters
Seconds YES 0-59 , - * /
Minutes YES 0-59 , - * /
Hours YES 0-23 , - * /
Day of month YES 1-31 , - * ? / L W
Month YES 1-12 or JAN-DEC , - * /
Day of week YES 1-7 or SUN-SAT , - * ? / L #
Year NO empty, 1970- , - * /

Special characters

  • *: All values in a field (e.g., * in minutes = "every minute").
  • ?: No specific value; use when specifying one of two related fields (e.g., "10" in day-of- month, ? in day-of-week).
  • -: Range of values (e.g., 10-12 in hour = "hours 10, 11, and 12").
  • ,: List of values (e.g., MON,WED,FRI in day-of-week = "Monday, Wednesday, Friday").
  • /: Increments (e.g., 0/15 in sec; 1/3 in day-of-m).
  • L: Last day; meaning varies by field. Ranges or lists are not allowed with L.
    • Day-of-month: Last day of the month (e.g, L-3 is the third to last day of the month).
    • Day-of-week: Last day of the week (7 or SAT) when alone; "last xxx day" when used after another value (e.g., 6L = "last Friday").
  • W: Nearest weekday in the month to the given day (e.g., 15W = "nearest weekday to the 15th"). If 1W on Saturday, it fires Monday the 3rd. W only applies to a single day, not ranges or lists.
  • #: Nth weekday of the month (e.g., 6#3 = "third Friday"; 2#1 = "first Monday"). Firing does not occur if that nth weekday does not exist in the month.

1 The L and W characters can also be combined in the day-of-month field to yield LW, which translates to "last weekday of the month".

2 The names of months and days of the week are not case-sensitive. MON is the same as mon.

Distributed mode

The scheduler can use its own implementation of quartz.JobQueue to allow state sharing.
An example implementation of the job queue using the file system as a persistence layer can be found here.

Usage example

package main

import (
	"context"
	"log/slog"
	"net/http"
	"os"
	"time"

	"github.com/reugn/go-quartz/job"
	"github.com/reugn/go-quartz/logger"
	"github.com/reugn/go-quartz/quartz"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// create a scheduler using the logger configuration option
	slogLogger := slog.New(slog.NewTextHandler(os.Stdout, nil))
	scheduler, _ := quartz.NewStdScheduler(quartz.WithLogger(logger.NewSlogLogger(ctx, slogLogger)))

	// start the scheduler
	scheduler.Start(ctx)

	// create jobs
	cronTrigger, _ := quartz.NewCronTrigger("1/5 * * * * *")
	shellJob := job.NewShellJob("ls -la")

	request, _ := http.NewRequest(http.MethodGet, "https://worldtimeapi.org/api/timezone/utc", nil)
	curlJob := job.NewCurlJob(request)

	functionJob := job.NewFunctionJob(func(_ context.Context) (int, error) { return 1, nil })

	// register the jobs with the scheduler
	_ = scheduler.ScheduleJob(quartz.NewJobDetail(shellJob, quartz.NewJobKey("shellJob")),
		cronTrigger)
	_ = scheduler.ScheduleJob(quartz.NewJobDetail(curlJob, quartz.NewJobKey("curlJob")),
		quartz.NewSimpleTrigger(7*time.Second))
	_ = scheduler.ScheduleJob(quartz.NewJobDetail(functionJob, quartz.NewJobKey("functionJob")),
		quartz.NewSimpleTrigger(5*time.Second))

	// stop the scheduler
	scheduler.Stop()

	// wait for all workers to exit
	scheduler.Wait(ctx)
}

See the examples directory for additional code samples.

License

Licensed under the MIT License.

Frequently asked questions

Is go-quartz free to use?

go-quartz is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does go-quartz do?

Minimalist and zero-dependency scheduling library for Go

What is go-quartz written in?

go-quartz is primarily written in Go. Its source is publicly available at https://github.com/reugn/go-quartz, and it has 2,012 GitHub stars.