Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derekhjray/scheduler
This a simple and efficient task scheduler based on https://github.com/robfig/cron, and add some new features
https://github.com/derekhjray/scheduler
Last synced: 18 days ago
JSON representation
This a simple and efficient task scheduler based on https://github.com/robfig/cron, and add some new features
- Host: GitHub
- URL: https://github.com/derekhjray/scheduler
- Owner: derekhjray
- License: mit
- Created: 2021-07-12T14:12:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-12T15:20:09.000Z (over 3 years ago)
- Last Synced: 2024-11-09T05:07:36.824Z (2 months ago)
- Language: Go
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Scheduler
This a simple and efficient job scheduler based on https://github.com/robfig/cron, support most of cron features and add some new features---
# Features
- Schedule a periodically job with spec
- Schedule a delayed periodically job with delay duration and spec
- Schedule a delayed job execute only once
- Unschedule a job, and cancel running task with context.CancelFunc
- Reschedule a job with new spec
- Specify goroutine count that used to executing jobs
- Specify a customed timezone# Installation
```bash
go get github.com/derekhjray/scheduler
```# Usage
```go
import (
"log"
"github.com/derekhjray/scheduler"
)func main() {
// use 8 goroutines at most
opt := scheduler.WithGoroutines(8)
s := scheduler.New(opt)s.Schedule(10, func(ctx context.Context) { log.Println("Execute a job after 10 seconds") })
s.Schedule("@hourly", func(ctx context.Context) { log.Println("Execute a job every hour") })
s.Schedule("*/15 * * * * *", func(ctx context.Context) { log.Println("Execute a job every 15 seconds") })
s.Schedule(10, "*/15 * * * * *", func(ctx context.Context) { log.Println("Execute a job after 10 seconds for the first time, and every 15 seconds after") })...
s.Unschedule(ids...) // Unschedule jobs, and cancel running job with context
s.Reschedule(id, spec) // Reschedule a job with a new spec
}
```