https://github.com/lesiw/chrono
Package chrono schedules chronoroutines: durable cron jobs backed by data stores.
https://github.com/lesiw/chrono
cron cronjob cronjob-scheduler go go-library golang golang-library
Last synced: 3 months ago
JSON representation
Package chrono schedules chronoroutines: durable cron jobs backed by data stores.
- Host: GitHub
- URL: https://github.com/lesiw/chrono
- Owner: lesiw
- License: mit
- Created: 2025-02-02T23:58:41.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-02-11T14:16:39.000Z (8 months ago)
- Last Synced: 2025-03-03T16:44:34.357Z (7 months ago)
- Topics: cron, cronjob, cronjob-scheduler, go, go-library, golang, golang-library
- Language: Go
- Homepage: https://lesiw.io/chrono
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/lesiw.io/chrono)# lesiw.io/chrono
A simple cronjob scheduler to handle job execution across multiple running
copies of an application. Currently only `github.com/jackc/pgx/v5` is supported
as a backing store.Instead of _goroutines_, `lesiw.io/chrono` schedules _chronoroutines_. Like
goroutines, chronoroutines have a deliberately simple API and offer little
configuration about how they are executed beyond their cron expression.If a node dies partway through job execution, the job will be restarted by
another node after a minute of missing heartbeats.Jobs do not immediately fire upon being scheduled. However, if
`lesiw.io/chrono` detects that a cron tick was missed, it will execute the
missed job immediately.For assistance with crontab syntax, check out https://crontab.guru.
## Minimal example
```go
package mainimport (
"context"
"log""github.com/jackc/pgx/v5"
"lesiw.io/chrono"
)func main() {
conn, err := pgx.Connect(context.Background(), "")
if err != nil {
log.Fatal(err)
}
cron := chrono.Pgx{Conn: conn}
if err := cron.Start(); err != nil {
log.Fatal(err)
}
err = cron.Go("example", "* * * * *", func() { println("hello world!") })
if err != nil {
log.Fatal(err)
}
select {}
}
```A `docker compose` example is available under
[internal/example](internal/example). Run `docker compose up` to build it.