Description
Define time-based tasks using a simple Go API and Gron’s scheduler will run them accordingly.
gron alternatives and similar packages
Based on the "Utilities" category.
Alternatively, view gron alternatives based on common mentions on social networks and blogs.
-
项目文档
基于vite+vue3+gin搭建的开发基础平台(支持TS,JS混用),集成jwt鉴权,权限管理,动态路由,显隐可控组件,分页封装,多点登录拦截,资源权限,上传下载,代码生成器,表单生成器,chatGPT自动查表等开发必备功能。 -
excelize
Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets -
godotenv
A Go port of Ruby's dotenv library (Loads environment variables from .env files) -
Kopia
Cross-platform backup tool for Windows, macOS & Linux with fast, incremental backups, client-side end-to-end encryption, compression and data deduplication. CLI and GUI included. -
go-funk
A modern Go utility library which provides helpers (map, find, contains, filter, ...) -
gorequest
GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent ) -
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report. -
gojson
Automatically generate Go (golang) struct definitions from example JSON -
create-go-app
✨ A complete and self-contained solution for developers of any qualification to create a production-ready project with backend (Go), frontend (JavaScript, TypeScript) and deploy automation (Ansible, Docker) by running only one CLI command. -
spinner
Go (golang) package with 90 configurable terminal spinner/progress indicators. -
EaseProbe
A simple, standalone, and lightweight tool that can do health/status checking, written in Go. -
filetype
Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature -
boilr
:zap: boilerplate template manager that generates files or directories from template repositories -
mole
CLI application to create ssh tunnels focused on resiliency and user experience. -
beaver
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps. -
mimetype
A fast Golang library for media type and file extension detection, based on magic numbers -
go-underscore
Helpfully Functional Go - A useful collection of Go utilities. Designed for programmer happiness. -
JobRunner
Framework for performing work asynchronously, outside of the request flow
Collect and Analyze Billions of Data Points in Real Time
Do you think we are missing an alternative of gron or a related project?
Popular Comparisons
README
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
$ go get github.com/roylee0704/gron
Usage
Create schedule.go
package main
import (
"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).
Setup basic periodic schedule with gron.Every()
.
gron.Every(1*time.Second)
gron.Every(1*time.Minute)
gron.Every(1*time.Hour)
Also support Day
, Week
by importing gron/xtime
:
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)
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:
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.
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.
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
package main
import (
"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()
}