go-sche is a golang library that lets you schedule your task to be executed later.

go-sche

codecov

go-sche is a golang library that lets you schedule your task to be executed later.

You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database like postgres, they will also survive scheduler restarts and maintain their state.

When the scheduler restarted, it will then run all the jobs it should have run while it was offline.

|—————————————|                          notify by gonal
|  scheduler  | ————————> task
   
     |-----------------> label |-----> handler
|—————————————|                        |                         |-----> handler
       |  interface                    |                         |-----> handler
|—————————————|                        |          
|    store    |                        |-----------------> label |-----> handler
|—————————————|                        |                         | ...
       |  next run time                | ...
|—————————————|
|    task     |
|—————————————|
       |  last run time
|—————————————|
|  cron-trig  |
|—————————————|

   

demo

package main

import (
	"context"
	"fmt"
	"github.com/czasg/go-sche"
	"github.com/czasg/gonal"
	"time"
)

func worker1(ctx context.Context, payload gonal.Payload) {
	fmt.Println("worker1", payload.Label, time.Now())
}

func worker2(ctx context.Context, payload gonal.Payload) {
	fmt.Println("worker2", payload.Label, time.Now())
}

func init() {
	// bind task with labels by gonal.
	gonal.Bind(worker1, gonal.Label{"func": "worker1"})
	gonal.Bind(worker2, gonal.Label{"func": "worker2"})
}

func main() {
	// init
	scheduler := sche.Scheduler{}
	// add task
	_ = scheduler.AddTask(&sche.Task{
		Name: "task1",
		Trig: "*/20 * * * *",
		Label: map[string]string{
			"func":       "worker1",
			"meta.other": "test1",
		},
	})
	_ = scheduler.AddTask(&sche.Task{
		Name: "task2",
		Trig: "15 * * * *",
		Label: map[string]string{
			"func":       "worker2",
			"meta.other": "test2",
		},
	})
	// start with block.
	scheduler.Start(context.Background())
}

more

using postgres

package main

import (
	"context"
	"github.com/czasg/go-sche"
)

func main() {
	pg := NewPG()
	
	scheduler := sche.Scheduler{
		Store: sche.NewPostgresStore(pg),
	}
	scheduler.Start(context.Background())
}
Owner
cza
Look for the truth. and Answer Is Python&Go!
cza
Similar Resources

Distributed Task Scheduling System|分布式定时任务调度平台

Distributed Task Scheduling System|分布式定时任务调度平台

Crocodile Distributed Task Scheduling System English | 中文 Introduction A distributed task scheduling system based on Golang that supports http request

Jan 5, 2023

Go based task runner

Grift Grift is a very simple library that allows you to write simple "task" scripts in Go and run them by name without having to write big main type o

Nov 21, 2022

go task pool

Task Pool Task Pool 是一个易于使用且高度可配置的 golang类库,专门用于任务的管理&执行,支持自定义次数的重发。 功能特点 线程安全 - task pool 内所有的方法以及暴露的接口都是线程安全的 异步发送 - 调用 PushTask 方法后回立即返回,任务将会被传递到io

Dec 29, 2022

Celery Distributed Task Queue in Go

Celery Distributed Task Queue in Go

gocelery Go Client/Server for Celery Distributed Task Queue Why? Having been involved in several projects migrating servers from Python to Go, I have

Jan 1, 2023

Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Dec 24, 2022

high performance distributed task scheduling system, Support multi protocol scheduling tasks

 high performance distributed task scheduling system, Support multi protocol scheduling tasks

high performance distributed task scheduling system, Support multi protocol scheduling tasks

Dec 2, 2022

Go distributed task scheduler

Go distributed task scheduler

Nov 13, 2021

A cross-platform task runner for executing commands and generating files from templates

A cross-platform task runner for executing commands and generating files from templates

Orbit A cross-platform task runner for executing commands and generating files from templates Orbit started with the need to find a cross-platform alt

Oct 22, 2022

You had one job, or more then one, which can be done in steps

Leprechaun Leprechaun is tool where you can schedule your recurring tasks to be performed over and over. In Leprechaun tasks are recipes, lets observe

Nov 23, 2022
Run Jobs on a schedule, supports fixed interval, timely, and cron-expression timers; Instrument your processes and expose metrics for each job.

A simple process manager that allows you to specify a Schedule that execute a Job based on a Timer. Schedule manage the state of this job allowing you to start/stop/restart in concurrent safe way. Schedule also instrument this Job and gather metrics and optionally expose them via uber-go/tally scope.

Dec 8, 2022
A command that someone swastikas when executed
A command that someone swastikas when executed

bankaiコマンド 実行すると誰かが卍解するコマンドです。 使い方 1. Homebrewでインストール brew tap krpk1900/bankai b

May 10, 2022
Reminder is a Golang package to allow users to schedule alerts.

Reminder is a Golang package to allow users to schedule alerts. It has 4 parts: Scheduler Repeater Notifier Reminder A scheduler takes in a t

Sep 28, 2022
Task Timer (tt) is a dead simple TUI task timer
Task Timer (tt) is a dead simple TUI task timer

tasktimer Task Timer (tt) is a dead simple TUI task timer Usage To get started, just run tt: tt You'll be presented with something like this: You can

Dec 21, 2022
Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function
Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

gotask The simple task queue is stripped when the program is written to achieve

Feb 14, 2022
Easily schedule commands to run multiple times at set intervals (like a cronjob, but with one command)

hakcron Easily schedule commands to run multiple times at set intervals (like a cronjob, but for a single command) Description hakcron allows you to r

Aug 17, 2022
Crane scheduler is a Kubernetes scheduler which can schedule pod based on actual node load.

Crane-scheduler Overview Crane-scheduler is a collection of scheduler plugins based on scheduler framework, including: Dynamic scheuler: a load-aware

Dec 29, 2022
YTask is an asynchronous task queue for handling distributed jobs in golang
YTask is an asynchronous task queue for handling distributed jobs in golang

YTask is an asynchronous task queue for handling distributed jobs in golang

Dec 24, 2022
goInterLock is golang job/task scheduler with distributed locking mechanism (by Using Redis🔒).
goInterLock is golang job/task scheduler with distributed locking mechanism (by Using Redis🔒).

goInterLock is golang job/task scheduler with distributed locking mechanism. In distributed system locking is preventing task been executed in every instant that has the scheduler,

Dec 5, 2022
Tasks - Golang CLI, Task manager

Tasks Golang CLI, Task manager Prerequisites Golang Setup environment variables

Jan 30, 2022