Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roylee0704/gron
gron, Cron Jobs in Go.
https://github.com/roylee0704/gron
cron-jobs golang scheduling
Last synced: about 1 month ago
JSON representation
gron, Cron Jobs in Go.
- Host: GitHub
- URL: https://github.com/roylee0704/gron
- Owner: roylee0704
- License: mit
- Created: 2016-06-04T08:02:22.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-05T07:44:19.000Z (about 1 year ago)
- Last Synced: 2024-01-30T04:49:17.415Z (4 months ago)
- Topics: cron-jobs, golang, scheduling
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 1,005
- Watchers: 15
- Forks: 66
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go-extra - gron - 06-04T08:02:22Z|2021-01-14T08:44:12Z| (Job Scheduler / Advanced Console UIs)
- awesome-go-zh - gron
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-stars - gron
- awesome-stars - roylee0704/gron - gron, Cron Jobs in Go. (Go)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. Stars:`1.0K`. (Job Scheduler / Search and Analytic Databases)
- awesome-go-cn - gron
- awesome-go-projects - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Standard CLI)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go-with-framework - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go-cn - gron
- go-awesome-cn-star - gron
- awesome-go-cn - gron
- awesome-go. - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Utilities / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Utilities / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-cn - gron - 使用简单的 Go 语言 API 和 Gron 调度器创建定时任务 (实用工具 / 高级控制台界面)
- awesome-go-with-stars - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- repo-1316-awesome-go-cn - gron
- repo-1211-awesome-go-cn - gron
- awesome-Char - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-reader - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go-stars - gron(stars: 1011) - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- Go-awesome - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Utilities / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Utilities / Advanced Console UIs)
- awesome-stars - roylee0704/gron - gron, Cron Jobs in Go. (Go)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go-handwritten - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Utilities / HTTP Clients)
- awesome-go - gron - 使用簡單的 Go 語言 API 和 Gron 調度器創建定時任務 (實用工具 / 高級控制台界面)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go - gron - gron, Cron Jobs in Go. - ★ 530 (Utilities)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go2 - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Utilities / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. - :arrow_down:7 - :star:442 (Job Scheduler / Advanced Console UIs)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Advanced Console UIs)
- awesome-go-zh - gron
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go-cn - gron
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go - gron - Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly. (Job Scheduler / Search and Analytic Databases)
- awesome-go-cn - gron - based tasks using a simple Go API and Gron’s scheduler will run them accordingly.) (实用工具 / Advanced Console UIs)
- awesome-go - gron - based tasks using a simple Go API and Gron’s scheduler will run them accordingly. | - | - | - | (Job Scheduler / Advanced Console UIs)
README
# gron
[![Build Status](https://semaphoreci.com/api/v1/roylee0704/gron/branches/master/badge.svg)](https://semaphoreci.com/roylee0704/gron)
[![Go Report Card](https://goreportcard.com/badge/github.com/roylee0704/gron)](https://goreportcard.com/report/github.com/roylee0704/gron)
[![GoDoc](https://godoc.org/github.com/roylee0704/gron?status.svg)](https://godoc.org/github.com/roylee0704/gron)Gron provides a clear syntax for writing and deploying cron jobs.
## Goals
- Minimalist APIs for scheduling jobs.
- Thread safety.
- Customizable Job Type.
- Customizable Schedule.## Installation
```sh
$ go get github.com/roylee0704/gron
```## Usage
Create `schedule.go````go
package mainimport (
"fmt"
"time"
"github.com/roylee0704/gron"
)func main() {
c := gron.New()
c.AddFunc(gron.Every(1*time.Hour), func() {
fmt.Println("runs every hour.")
})
c.Start()
}
```#### Schedule Parameters
All scheduling is done in the machine's local time zone (as provided by the Go [time package](http://www.golang.org/pkg/time)).
Setup basic periodic schedule with `gron.Every()`.
```go
gron.Every(1*time.Second)
gron.Every(1*time.Minute)
gron.Every(1*time.Hour)
```Also support `Day`, `Week` by importing `gron/xtime`:
```go
import "github.com/roylee0704/gron/xtime"gron.Every(1 * xtime.Day)
gron.Every(1 * xtime.Week)
```Schedule to run at specific time with `.At(hh:mm)`
```go
gron.Every(30 * xtime.Day).At("00:00")
gron.Every(1 * xtime.Week).At("23:59")
```#### Custom Job Type
You may define custom job types by implementing `gron.Job` interface: `Run()`.For example:
```go
type Reminder struct {
Msg string
}func (r Reminder) Run() {
fmt.Println(r.Msg)
}
```After job has defined, instantiate it and schedule to run in Gron.
```go
c := gron.New()
r := Reminder{ "Feed the baby!" }
c.Add(gron.Every(8*time.Hour), r)
c.Start()
```#### Custom Job Func
You may register `Funcs` to be executed on a given schedule. Gron will run them in their own goroutines, asynchronously.```go
c := gron.New()
c.AddFunc(gron.Every(1*time.Second), func() {
fmt.Println("runs every second")
})
c.Start()
```#### Custom Schedule
Schedule is the interface that wraps the basic `Next` method: `Next(p time.Duration) time.Time`In `gron`, the interface value `Schedule` has the following concrete types:
- **periodicSchedule**. adds time instant t to underlying period p.
- **atSchedule**. reoccurs every period p, at time components(hh:mm).For more info, checkout `schedule.go`.
### Full Example
```go
package mainimport (
"fmt"
"github.com/roylee0704/gron"
"github.com/roylee0704/gron/xtime"
)type PrintJob struct{ Msg string }
func (p PrintJob) Run() {
fmt.Println(p.Msg)
}func main() {
var (
// schedules
daily = gron.Every(1 * xtime.Day)
weekly = gron.Every(1 * xtime.Week)
monthly = gron.Every(30 * xtime.Day)
yearly = gron.Every(365 * xtime.Day)// contrived jobs
purgeTask = func() { fmt.Println("purge aged records") }
printFoo = printJob{"Foo"}
printBar = printJob{"Bar"}
)c := gron.New()
c.Add(daily.At("12:30"), printFoo)
c.AddFunc(weekly, func() { fmt.Println("Every week") })
c.Start()// Jobs may also be added to a running Gron
c.Add(monthly, printBar)
c.AddFunc(yearly, purgeTask)// Stop Gron (running jobs are not halted).
c.Stop()
}
```