{"id":13413239,"url":"https://github.com/roylee0704/gron","last_synced_at":"2025-05-16T08:05:15.938Z","repository":{"id":44844894,"uuid":"60399899","full_name":"roylee0704/gron","owner":"roylee0704","description":"gron, Cron Jobs in Go.","archived":false,"fork":false,"pushed_at":"2023-05-05T07:44:19.000Z","size":51,"stargazers_count":1036,"open_issues_count":9,"forks_count":64,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-08T19:25:42.798Z","etag":null,"topics":["cron-jobs","golang","scheduling"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roylee0704.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-06-04T08:02:22.000Z","updated_at":"2025-03-31T14:59:11.000Z","dependencies_parsed_at":"2023-01-21T01:15:39.906Z","dependency_job_id":"c254f7ed-485e-4692-adc3-e877faa5d9d4","html_url":"https://github.com/roylee0704/gron","commit_stats":{"total_commits":122,"total_committers":1,"mean_commits":122.0,"dds":0.0,"last_synced_commit":"e78485adab469c8f47aef96f6afff89bb1228400"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roylee0704%2Fgron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roylee0704%2Fgron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roylee0704%2Fgron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roylee0704%2Fgron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roylee0704","download_url":"https://codeload.github.com/roylee0704/gron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493378,"owners_count":22080126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron-jobs","golang","scheduling"],"created_at":"2024-07-30T20:01:35.854Z","updated_at":"2025-05-16T08:05:10.930Z","avatar_url":"https://github.com/roylee0704.png","language":"Go","funding_links":[],"categories":["Go","Job Scheduler","Utilities","Relational Databases","任务调度","作业调度器","作业调度","实用工具","實用工具","工具库"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库","高级控制台界面","高級控制台界面","HTTP Clients","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"# gron\n[![Build Status](https://semaphoreci.com/api/v1/roylee0704/gron/branches/master/badge.svg)](https://semaphoreci.com/roylee0704/gron)\n[![Go Report Card](https://goreportcard.com/badge/github.com/roylee0704/gron)](https://goreportcard.com/report/github.com/roylee0704/gron)\n[![GoDoc](https://godoc.org/github.com/roylee0704/gron?status.svg)](https://godoc.org/github.com/roylee0704/gron)\n\nGron provides a clear syntax for writing and deploying cron jobs.\n\n## Goals\n\n- Minimalist APIs for scheduling jobs.\n- Thread safety.\n- Customizable Job Type.\n- Customizable Schedule.\n\n## Installation\n\n```sh\n$ go get github.com/roylee0704/gron\n```\n\n## Usage\nCreate `schedule.go`\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\t\"github.com/roylee0704/gron\"\n)\n\nfunc main() {\n\tc := gron.New()\n\tc.AddFunc(gron.Every(1*time.Hour), func() {\n\t\tfmt.Println(\"runs every hour.\")\n\t})\n\tc.Start()\n}\n```\n\n#### Schedule Parameters\n\nAll scheduling is done in the machine's local time zone (as provided by the Go [time package](http://www.golang.org/pkg/time)).\n\n\nSetup basic periodic schedule with `gron.Every()`.\n\n```go\ngron.Every(1*time.Second)\ngron.Every(1*time.Minute)\ngron.Every(1*time.Hour)\n```\n\nAlso support `Day`, `Week` by importing `gron/xtime`:\n```go\nimport \"github.com/roylee0704/gron/xtime\"\n\ngron.Every(1 * xtime.Day)\ngron.Every(1 * xtime.Week)\n```\n\nSchedule to run at specific time with `.At(hh:mm)`\n```go\ngron.Every(30 * xtime.Day).At(\"00:00\")\ngron.Every(1 * xtime.Week).At(\"23:59\")\n```\n\n#### Custom Job Type\nYou may define custom job types by implementing `gron.Job` interface: `Run()`.\n\nFor example:\n\n```go\ntype Reminder struct {\n\tMsg string\n}\n\nfunc (r Reminder) Run() {\n  fmt.Println(r.Msg)\n}\n```\n\nAfter job has defined, instantiate it and schedule to run in Gron.\n```go\nc := gron.New()\nr := Reminder{ \"Feed the baby!\" }\nc.Add(gron.Every(8*time.Hour), r)\nc.Start()\n```\n\n#### Custom Job Func\nYou may register `Funcs` to be executed on a given schedule. Gron will run them in their own goroutines, asynchronously.\n\n```go\nc := gron.New()\nc.AddFunc(gron.Every(1*time.Second), func() {\n\tfmt.Println(\"runs every second\")\n})\nc.Start()\n```\n\n\n#### Custom Schedule\nSchedule is the interface that wraps the basic `Next` method: `Next(p time.Duration) time.Time`\n\nIn `gron`, the interface value `Schedule` has the following concrete types:\n\n- **periodicSchedule**. adds time instant t to underlying period p.\n- **atSchedule**. reoccurs every period p, at time components(hh:mm).\n\nFor more info, checkout `schedule.go`.\n\n### Full Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/roylee0704/gron\"\n\t\"github.com/roylee0704/gron/xtime\"\n)\n\ntype PrintJob struct{ Msg string }\n\nfunc (p PrintJob) Run() {\n\tfmt.Println(p.Msg)\n}\n\nfunc main() {\n\n\tvar (\n\t\t// schedules\n\t\tdaily     = gron.Every(1 * xtime.Day)\n\t\tweekly    = gron.Every(1 * xtime.Week)\n\t\tmonthly   = gron.Every(30 * xtime.Day)\n\t\tyearly    = gron.Every(365 * xtime.Day)\n\n\t\t// contrived jobs\n\t\tpurgeTask = func() { fmt.Println(\"purge aged records\") }\n\t\tprintFoo  = printJob{\"Foo\"}\n\t\tprintBar  = printJob{\"Bar\"}\n\t)\n\n\tc := gron.New()\n\n\tc.Add(daily.At(\"12:30\"), printFoo)\n\tc.AddFunc(weekly, func() { fmt.Println(\"Every week\") })\n\tc.Start()\n\n\t// Jobs may also be added to a running Gron\n\tc.Add(monthly, printBar)\n\tc.AddFunc(yearly, purgeTask)\n\n\t// Stop Gron (running jobs are not halted).\n\tc.Stop()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froylee0704%2Fgron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froylee0704%2Fgron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froylee0704%2Fgron/lists"}