{"id":13413237,"url":"https://github.com/go-co-op/gocron","last_synced_at":"2025-05-12T13:05:12.810Z","repository":{"id":37699653,"uuid":"248790367","full_name":"go-co-op/gocron","owner":"go-co-op","description":"Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron","archived":false,"fork":false,"pushed_at":"2025-05-05T19:27:07.000Z","size":881,"stargazers_count":6194,"open_issues_count":17,"forks_count":327,"subscribers_count":37,"default_branch":"v2","last_synced_at":"2025-05-12T13:04:48.930Z","etag":null,"topics":["clockwork","cron","gocron","golang","golang-job-scheduling","hacktoberfest","schedule","scheduler"],"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/go-co-op.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":null,"patreon":null,"open_collective":"gocron","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-03-20T15:33:05.000Z","updated_at":"2025-05-12T08:07:36.000Z","dependencies_parsed_at":"2023-10-27T13:28:53.487Z","dependency_job_id":"a6f804d6-53b3-437f-af3e-9665f5483015","html_url":"https://github.com/go-co-op/gocron","commit_stats":{"total_commits":103,"total_committers":19,"mean_commits":5.421052631578948,"dds":"0.35922330097087374","last_synced_commit":"31de1e81082a5fe6ea66f9c148fc437bdcf079bf"},"previous_names":[],"tags_count":144,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-co-op%2Fgocron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-co-op%2Fgocron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-co-op%2Fgocron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-co-op%2Fgocron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-co-op","download_url":"https://codeload.github.com/go-co-op/gocron/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745117,"owners_count":21957317,"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":["clockwork","cron","gocron","golang","golang-job-scheduling","hacktoberfest","schedule","scheduler"],"created_at":"2024-07-30T20:01:35.817Z","updated_at":"2025-05-12T13:05:12.740Z","avatar_url":"https://github.com/go-co-op.png","language":"Go","funding_links":["https://opencollective.com/gocron"],"categories":["Job Scheduler","Go","开源类库","作业调度器","Relational Databases","任务调度","作业调度"],"sub_categories":["Search and Analytic Databases","任务/定时器","检索及分析资料库","Advanced Console UIs","SQL 查询语句构建库"],"readme":"# gocron: A Golang Job Scheduling Package\n\n[![CI State](https://github.com/go-co-op/gocron/actions/workflows/go_test.yml/badge.svg?branch=v2\u0026event=push)](https://github.com/go-co-op/gocron/actions)\n![Go Report Card](https://goreportcard.com/badge/github.com/go-co-op/gocron) [![Go Doc](https://godoc.org/github.com/go-co-op/gocron/v2?status.svg)](https://pkg.go.dev/github.com/go-co-op/gocron/v2)\n\ngocron is a job scheduling package which lets you run Go functions at pre-determined intervals.\n\nIf you want to chat, you can find us on Slack at\n[\u003cimg src=\"https://img.shields.io/badge/gophers-gocron-brightgreen?logo=slack\"\u003e](https://gophers.slack.com/archives/CQ7T0T1FW)\n\n## Quick Start\n\n```\ngo get github.com/go-co-op/gocron/v2\n```\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/go-co-op/gocron/v2\"\n)\n\nfunc main() {\n\t// create a scheduler\n\ts, err := gocron.NewScheduler()\n\tif err != nil {\n\t\t// handle error\n\t}\n\n\t// add a job to the scheduler\n\tj, err := s.NewJob(\n\t\tgocron.DurationJob(\n\t\t\t10*time.Second,\n\t\t),\n\t\tgocron.NewTask(\n\t\t\tfunc(a string, b int) {\n\t\t\t\t// do things\n\t\t\t},\n\t\t\t\"hello\",\n\t\t\t1,\n\t\t),\n\t)\n\tif err != nil {\n\t\t// handle error\n\t}\n\t// each job has a unique id\n\tfmt.Println(j.ID())\n\n\t// start the scheduler\n\ts.Start()\n\n\t// block until you are ready to shut down\n\tselect {\n\tcase \u003c-time.After(time.Minute):\n\t}\n\n\t// when you're done, shut it down\n\terr = s.Shutdown()\n\tif err != nil {\n\t\t// handle error\n\t}\n}\n```\n\n## Examples\n\n- [Go doc examples](https://pkg.go.dev/github.com/go-co-op/gocron/v2#pkg-examples)\n- [Examples directory](examples)\n\n## Concepts\n\n- **Job**: The job encapsulates a \"task\", which is made up of a go function and any function parameters. The Job then\n  provides the scheduler with the time the job should next be scheduled to run.\n- **Scheduler**: The scheduler keeps track of all the jobs and sends each job to the executor when\n  it is ready to be run.\n- **Executor**: The executor calls the job's task and manages the complexities of different job\n  execution timing requirements (e.g. singletons that shouldn't overrun each other, limiting the max number of jobs running)\n\n\n## Features\n\n### Job types\nJobs can be run at various intervals.\n- [**Duration**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#DurationJob):\nJobs can be run at a fixed `time.Duration`.\n- [**Random duration**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#DurationRandomJob):\nJobs can be run at a random `time.Duration` between a min and max.\n- [**Cron**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#CronJob):\nJobs can be run using a crontab.\n- [**Daily**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#DailyJob):\nJobs can be run every x days at specific times.\n- [**Weekly**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WeeklyJob):\nJobs can be run every x weeks on specific days of the week and at specific times.\n- [**Monthly**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#MonthlyJob):\nJobs can be run every x months on specific days of the month and at specific times.\n- [**One time**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#OneTimeJob):\nJobs can be run at specific time(s) (either once or many times).\n\n### Concurrency Limits\nJobs can be limited individually or across the entire scheduler.\n- [**Per job limiting with singleton mode**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithSingletonMode):\nJobs can be limited to a single concurrent execution that either reschedules (skips overlapping executions)\nor queues (waits for the previous execution to finish).\n- [**Per scheduler limiting with limit mode**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithLimitConcurrentJobs):\nJobs can be limited to a certain number of concurrent executions across the entire scheduler\nusing either reschedule (skip when the limit is met) or queue (jobs are added to a queue to\nwait for the limit to be available).\n- **Note:** A scheduler limit and a job limit can both be enabled.\n\n### Distributed instances of gocron\nMultiple instances of gocron can be run.\n- [**Elector**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithDistributedElector):\nAn elector can be used to elect a single instance of gocron to run as the primary with the\nother instances checking to see if a new leader needs to be elected.\n  - Implementations: [go-co-op electors](https://github.com/go-co-op?q=-elector\u0026type=all\u0026language=\u0026sort=)\n    (don't see what you need? request on slack to get a repo created to contribute it!)\n- [**Locker**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithDistributedLocker):\nA locker can be used to lock each run of a job to a single instance of gocron.\nLocker can be at job or scheduler, if it is defined both at job and scheduler then locker of job will take precedence.\n  - Implementations: [go-co-op lockers](https://github.com/go-co-op?q=-lock\u0026type=all\u0026language=\u0026sort=)\n    (don't see what you need? request on slack to get a repo created to contribute it!)\n\n### Events\nJob events can trigger actions.\n- [**Listeners**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithEventListeners):\nCan be added to a job, with [event listeners](https://pkg.go.dev/github.com/go-co-op/gocron/v2#EventListener),\nor all jobs across the\n[scheduler](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithGlobalJobOptions)\nto listen for job events and trigger actions.\n\n### Options\nMany job and scheduler options are available.\n- [**Job options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#JobOption):\nJob options can be set when creating a job using `NewJob`.\n- [**Global job options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithGlobalJobOptions):\nGlobal job options can be set when creating a scheduler using `NewScheduler`\nand the `WithGlobalJobOptions` option.\n- [**Scheduler options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#SchedulerOption):\nScheduler options can be set when creating a scheduler using `NewScheduler`.\n\n### Logging\nLogs can be enabled.\n- [Logger](https://pkg.go.dev/github.com/go-co-op/gocron/v2#Logger):\nThe Logger interface can be implemented with your desired logging library.\nThe provided NewLogger uses the standard library's log package.\n\n### Metrics\nMetrics may be collected from the execution of each job.\n- [**Monitor**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#Monitor):\n- [**MonitorStatus**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#MonitorStatus) (includes status and error (if any) of the Job)\nA monitor can be used to collect metrics for each job from a scheduler.\n  - Implementations: [go-co-op monitors](https://github.com/go-co-op?q=-monitor\u0026type=all\u0026language=\u0026sort=)\n    (don't see what you need? request on slack to get a repo created to contribute it!)\n\n### Testing\nThe gocron library is set up to enable testing.\n- Mocks are provided in [the mock package](mocks) using [gomock](https://github.com/uber-go/mock).\n- Time can be mocked by passing in a [FakeClock](https://pkg.go.dev/github.com/jonboulle/clockwork#FakeClock)\nto [WithClock](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithClock) -\nsee the [example on WithClock](https://pkg.go.dev/github.com/go-co-op/gocron/v2#example-WithClock).\n\n## Supporters\n\nWe appreciate the support for free and open source software!\n\nThis project is supported by:\n\n[JetBrains](https://www.jetbrains.com/?from=gocron)\n\n\u003ca href=\"https://www.jetbrains.com/?from=gocron\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"assets/jetbrains-mono-white.png\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png\" /\u003e\n   \u003cimg alt=\"JetBrains logo\" src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n\n[Sentry](https://sentry.io/welcome/)\n\n\u003ca href=\"https://sentry.io/?utm_source=github\u0026utm_medium=logo\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"assets/sentry-wordmark-light-280x84.png\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png\" /\u003e\n   \u003cimg alt=\"Sentry logo\" src=\"https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n\n## Star History\n\n\u003ca href=\"https://www.star-history.com/#go-co-op/gocron\u0026Date\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=go-co-op/gocron\u0026type=Date\u0026theme=dark\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=go-co-op/gocron\u0026type=Date\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=go-co-op/gocron\u0026type=Date\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-co-op%2Fgocron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-co-op%2Fgocron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-co-op%2Fgocron/lists"}