{"id":13413236,"url":"https://github.com/reugn/go-quartz","last_synced_at":"2025-05-14T00:07:15.709Z","repository":{"id":37431286,"uuid":"181355200","full_name":"reugn/go-quartz","owner":"reugn","description":"Minimalist and zero-dependency scheduling library for Go","archived":false,"fork":false,"pushed_at":"2025-03-03T17:54:02.000Z","size":254,"stargazers_count":1856,"open_issues_count":2,"forks_count":87,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-10T13:11:01.915Z","etag":null,"topics":["cron","cronjob","crontab","go","golang","job","job-queue","job-scheduler","jobqueue","quartz","quartz-scheduler","scheduler","task","task-scheduler","zero-dependency"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/reugn/go-quartz/quartz","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/reugn.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-14T18:57:51.000Z","updated_at":"2025-04-04T19:38:18.000Z","dependencies_parsed_at":"2023-10-24T19:25:37.580Z","dependency_job_id":"be969984-27fc-4c2e-90bc-e6696ac54a3e","html_url":"https://github.com/reugn/go-quartz","commit_stats":{"total_commits":153,"total_committers":9,"mean_commits":17.0,"dds":"0.10457516339869277","last_synced_commit":"62266744c37cdf2815621bfa7233d6f15062a346"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-quartz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-quartz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-quartz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-quartz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reugn","download_url":"https://codeload.github.com/reugn/go-quartz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043711,"owners_count":22004999,"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","cronjob","crontab","go","golang","job","job-queue","job-scheduler","jobqueue","quartz","quartz-scheduler","scheduler","task","task-scheduler","zero-dependency"],"created_at":"2024-07-30T20:01:35.799Z","updated_at":"2025-05-14T00:07:15.690Z","avatar_url":"https://github.com/reugn.png","language":"Go","readme":"# go-quartz\n\n[![Build](https://github.com/reugn/go-quartz/actions/workflows/build.yml/badge.svg)](https://github.com/reugn/go-quartz/actions/workflows/build.yml)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/reugn/go-quartz)](https://pkg.go.dev/github.com/reugn/go-quartz)\n[![Go Report Card](https://goreportcard.com/badge/github.com/reugn/go-quartz)](https://goreportcard.com/report/github.com/reugn/go-quartz)\n[![codecov](https://codecov.io/gh/reugn/go-quartz/branch/master/graph/badge.svg)](https://codecov.io/gh/reugn/go-quartz)\n\nA minimalistic and zero-dependency scheduling library for Go.\n\n## About\n\nThe implementation is inspired by the design of the [Quartz](https://github.com/quartz-scheduler/quartz)\nJava scheduler.\n\nThe core [scheduler](#scheduler-interface) component can be used to manage scheduled [jobs](#job-interface) (tasks)\nusing [triggers](#trigger-interface).\nThe implementation of the cron trigger fully supports the Quartz [cron expression format](#cron-expression-format)\nand can be used independently to calculate a future time given the previous execution time.\n\nIf you need to run multiple instances of the scheduler, see the [distributed mode](#distributed-mode) section for\nguidance.\n\n### Library building blocks\n\n#### Scheduler interface\n\n```go\ntype Scheduler interface {\n\t// Start starts the scheduler. The scheduler will run until\n\t// the Stop method is called or the context is canceled. Use\n\t// the Wait method to block until all running jobs have completed.\n\tStart(context.Context)\n\n\t// IsStarted determines whether the scheduler has been started.\n\tIsStarted() bool\n\n\t// ScheduleJob schedules a job using the provided Trigger.\n\tScheduleJob(jobDetail *JobDetail, trigger Trigger) error\n\n\t// GetJobKeys returns the keys of scheduled jobs.\n\t// For a job key to be returned, the job must satisfy all of the\n\t// matchers specified.\n\t// Given no matchers, it returns the keys of all scheduled jobs.\n\tGetJobKeys(...Matcher[ScheduledJob]) ([]*JobKey, error)\n\n\t// GetScheduledJob returns the scheduled job with the specified key.\n\tGetScheduledJob(jobKey *JobKey) (ScheduledJob, error)\n\n\t// DeleteJob removes the job with the specified key from the\n\t// scheduler's execution queue.\n\tDeleteJob(jobKey *JobKey) error\n\n\t// PauseJob suspends the job with the specified key from being\n\t// executed by the scheduler.\n\tPauseJob(jobKey *JobKey) error\n\n\t// ResumeJob restarts the suspended job with the specified key.\n\tResumeJob(jobKey *JobKey) error\n\n\t// Clear removes all of the scheduled jobs.\n\tClear() error\n\n\t// Wait blocks until the scheduler stops running and all jobs\n\t// have returned. Wait will return when the context passed to\n\t// it has expired. Until the context passed to start is\n\t// cancelled or Stop is called directly.\n\tWait(context.Context)\n\n\t// Stop shutdowns the scheduler.\n\tStop()\n}\n```\n\nImplemented Schedulers\n\n- StdScheduler\n\n#### Trigger interface\n\n```go\ntype Trigger interface {\n\t// NextFireTime returns the next time at which the Trigger is scheduled to fire.\n\tNextFireTime(prev int64) (int64, error)\n\n\t// Description returns the description of the Trigger.\n\tDescription() string\n}\n```\n\nImplemented Triggers\n\n- CronTrigger\n- SimpleTrigger\n- RunOnceTrigger\n\n#### Job interface\n\nAny type that implements it can be scheduled.\n\n```go\ntype Job interface {\n\t// Execute is called by a Scheduler when the Trigger associated with this job fires.\n\tExecute(context.Context) error\n\n\t// Description returns the description of the Job.\n\tDescription() string\n}\n```\n\nSeveral common Job implementations can be found in the [job](./job) package.\n\n## Cron expression format\n\n| Field Name   | Mandatory | Allowed Values  | Allowed Special Characters |\n|--------------|-----------|-----------------|----------------------------|\n| Seconds      | YES       | 0-59            | , - * /                    |\n| Minutes      | YES       | 0-59            | , - * /                    |\n| Hours        | YES       | 0-23            | , - * /                    |\n| Day of month | YES       | 1-31            | , - * ? / L W              |\n| Month        | YES       | 1-12 or JAN-DEC | , - * /                    |\n| Day of week  | YES       | 1-7 or SUN-SAT  | , - * ? / L #              |\n| Year         | NO        | empty, 1970-    | , - * /                    |\n\n### Special characters\n\n- `*`: All values in a field (e.g., `*` in minutes = \"every minute\").\n- `?`: No specific value; use when specifying one of two related fields (e.g., \"10\" in day-of- month, `?` in\n  day-of-week).\n- `-`: Range of values (e.g., `10-12` in hour = \"hours 10, 11, and 12\").\n- `,`: List of values (e.g., `MON,WED,FRI` in day-of-week = \"Monday, Wednesday, Friday\").\n- `/`: Increments (e.g., `0/15` in seconds = \"0, 15, 30, 45\"; `1/3` in day-of-month = \"every 3 days from the 1st\").\n- `L`: Last day; meaning varies by field. Ranges or lists are not allowed with `L`.\n  - Day-of-month: Last day of the month (e.g, `L-3` is the third to last day of the month).\n  - Day-of-week: Last day of the week (7 or SAT) when alone; \"last xxx day\" when used after\n    another value (e.g., `6L` = \"last Friday\").\n- `W`: Nearest weekday in the month to the given day (e.g., `15W` = \"nearest weekday to the 15th\"). If `1W` on\n  Saturday, it fires Monday the 3rd. `W` only applies to a single day, not ranges or lists.\n- `#`: Nth weekday of the month (e.g., `6#3` = \"third Friday\"; `2#1` = \"first Monday\"). Firing does not occur if\n  that nth weekday does not exist in the month.\n\n\u003csup\u003e1\u003c/sup\u003e The `L` and `W` characters can also be combined in the day-of-month field to yield `LW`, which\ntranslates to \"last weekday of the month\".\n\n\u003csup\u003e2\u003c/sup\u003e The names of months and days of the week are not case-sensitive. MON is the same as mon.\n\n## Distributed mode\n\nThe scheduler can use its own implementation of `quartz.JobQueue` to allow state sharing.  \nAn example implementation of the job queue using the file system as a persistence layer\ncan be found [here](./examples/queue/file_system.go).\n\n## Usage example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log/slog\"\n\t\"net/http\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/reugn/go-quartz/job\"\n\t\"github.com/reugn/go-quartz/logger\"\n\t\"github.com/reugn/go-quartz/quartz\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\t// create a scheduler using the logger configuration option\n\tslogLogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\tscheduler, _ := quartz.NewStdScheduler(quartz.WithLogger(logger.NewSlogLogger(ctx, slogLogger)))\n\n\t// start the scheduler\n\tscheduler.Start(ctx)\n\n\t// create jobs\n\tcronTrigger, _ := quartz.NewCronTrigger(\"1/5 * * * * *\")\n\tshellJob := job.NewShellJob(\"ls -la\")\n\n\trequest, _ := http.NewRequest(http.MethodGet, \"https://worldtimeapi.org/api/timezone/utc\", nil)\n\tcurlJob := job.NewCurlJob(request)\n\n\tfunctionJob := job.NewFunctionJob(func(_ context.Context) (int, error) { return 1, nil })\n\n\t// register the jobs with the scheduler\n\t_ = scheduler.ScheduleJob(quartz.NewJobDetail(shellJob, quartz.NewJobKey(\"shellJob\")),\n\t\tcronTrigger)\n\t_ = scheduler.ScheduleJob(quartz.NewJobDetail(curlJob, quartz.NewJobKey(\"curlJob\")),\n\t\tquartz.NewSimpleTrigger(7*time.Second))\n\t_ = scheduler.ScheduleJob(quartz.NewJobDetail(functionJob, quartz.NewJobKey(\"functionJob\")),\n\t\tquartz.NewSimpleTrigger(5*time.Second))\n\n\t// stop the scheduler\n\tscheduler.Stop()\n\n\t// wait for all workers to exit\n\tscheduler.Wait(ctx)\n}\n```\n\nSee the examples directory for additional code samples.\n\n## License\n\nLicensed under the MIT License.\n","funding_links":[],"categories":["Job Scheduler","Go","作业调度器","作业调度","Relational Databases","Repositories","Members"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freugn%2Fgo-quartz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freugn%2Fgo-quartz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freugn%2Fgo-quartz/lists"}