Skip to content
This repository has been archived by the owner. It is now read-only.
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Go Task Scheduler

Go Task scheduler is a small library that you can use within your application that enables you to execute callbacks (goroutines) after a pre-defined amount of time. GTS also provides task storage which is used to invoke callbacks for tasks which couldn’t be executed during down-time as well as maintaining a history of the callbacks that got executed.


  • Execute tasks based after a specific duration or at a specific point in time
  • Job stores for history & recovery, provided stores out of the box:
    • Sqlite3
    • Redis (Coming soon)


go get

How To Use

Instantiate a scheduler as follows:

s := scheduler.New(storage)

GTS currently supports 2 kinds of storages:

  1. NoOpStorage: Does nothing
noOpStorage := storage.NewNoOpStorage()
  1. MemoryStorage: Does nothing
memStorage := storage.NewMemoryStorage()
  1. SqliteStorage: Persists tasks into a SQLite3 database.
sqliteStorage := storage.NewSqlite3Storage()


storage := storage.NewSqlite3Storage(
		DbName: "",
if err := storage.Connect(); err != nil {
	log.Fatal("Could not connect to db", err)

if err := storage.Initialize(); err != nil {
	log.Fatal("Could not intialize database", err)

and then pass it to the scheduler.

Scheduling tasks can be done in 3 ways:

Execute a task after 5 seconds.

func MyFunc(arg1 string, arg2 string)
taskID := s.RunAfter(5*time.Second, MyFunc, "Hello", "World")

Execute a task at a specific time.

func MyFunc(arg1 string, arg2 string)
taskID := s.RunAt(time.Now().Add(24 * time.Hour), MyFunc, "Hello", "World")

Execute a task every 1 minute.

func MyFunc(arg1 string, arg2 string)
taskID := s.RunEvery(1 * time.Minute, MyFunc, "Hello", "World")


The Examples folder contains a bunch of code samples you can look into.

Custom Storage

GTS supports the ability to provide a custom storage, the newly created storage has to implement the TaskStore interface

type TaskStore interface {
	Store(task *TaskAttributes) error
        Remove(task *TaskAttributes) error
	Fetch() ([]TaskAttributes, error)

TaskAttributes looks as follows:

type TaskAttributes struct {
	Hash        string
	Name        string
	LastRun     string
	NextRun     string
	Duration    string
	IsRecurring string
	Params      string


  • [ ] Design a cron-like task schedule for RunEvery method


This package is heavily inspired by APScheduler for Python & GoCron



You can’t perform that action at this time.