{"id":34164440,"url":"https://github.com/raykavin/goschd","last_synced_at":"2026-03-11T11:07:36.803Z","repository":{"id":277602188,"uuid":"932949564","full_name":"raykavin/goschd","owner":"raykavin","description":"The Go Scheduler package provides a flexible and lightweight task scheduling mechanism for Go applications. You can schedule tasks to run periodically using either duration strings or cron expressions. ","archived":false,"fork":false,"pushed_at":"2025-10-20T17:03:52.000Z","size":117,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-18T05:40:02.722Z","etag":null,"topics":["background","cron","golang","jobber","scheduler","tasks"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raykavin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-14T20:29:07.000Z","updated_at":"2025-10-20T15:37:21.000Z","dependencies_parsed_at":"2025-08-24T18:06:54.023Z","dependency_job_id":"f1115237-03da-4422-9d38-0ae227899df7","html_url":"https://github.com/raykavin/goschd","commit_stats":null,"previous_names":["raykavin/schedulerext","raykavin/schd-go","raykavin/goschd"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/raykavin/goschd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raykavin%2Fgoschd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raykavin%2Fgoschd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raykavin%2Fgoschd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raykavin%2Fgoschd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raykavin","download_url":"https://codeload.github.com/raykavin/goschd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raykavin%2Fgoschd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30379267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["background","cron","golang","jobber","scheduler","tasks"],"created_at":"2025-12-15T09:51:05.516Z","updated_at":"2026-03-11T11:07:36.797Z","avatar_url":"https://github.com/raykavin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Scheduler Package\n\u003cp align=\"start\"\u003e\n  \u003cimg src=\"./assets/goschd.jpg\" alt=\"goschd\" width=\"350\"/\u003e\n\u003c/p\u003e\n\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/raykavin/goschd.svg)](https://pkg.go.dev/github.com/raykavin/goschd)\n[![Lint](https://github.com/raykavin/goschd/actions/workflows/lint.yml/badge.svg)](https://github.com/raykavin/goschd/actions/workflows/lint.yml)\n[![Build](https://github.com/raykavin/goschd/actions/workflows/build.yml/badge.svg)](https://github.com/raykavin/goschd/actions/workflows/build.yml)\n[![Go Version](https://img.shields.io/badge/go-1.24.3-blue)](https://golang.org/dl/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/raykavin/goschd)](https://goreportcard.com/report/github.com/raykavin/goschd)\n[![License](https://img.shields.io/badge/license-GPL-blue.svg)](LICENSE)\n\nThe Go Scheduler package provides a flexible and lightweight task scheduling mechanism for Go applications. You can schedule tasks to run periodically using either duration strings or cron expressions. It supports delayed starts, one-time execution, single-instance execution, and custom error handling.\n\n## Features\n\n- **Flexible Scheduling:**  \n  Schedule tasks using either standard Go duration strings (e.g., `\"1s\"`, `\"500ms\"`) or cron expressions (e.g., `\"* * * * * *\"`).\n\n- **Immediate or Delayed Start:**  \n  Configure tasks to start immediately (`FirstRun`) or at a later time using `StartAfter`.\n\n- **One-Time or Recurring Tasks:**  \n  Use `RunOnce` to run a task only once or leave it running repeatedly.\n\n- **Single Instance Execution:**  \n  Prevent concurrent execution of tasks with the `RunSingleInstance` flag.\n\n- **Error Handling:**  \n  Supply custom error handlers (`ErrFunc` or `ErrFuncWithTaskContext`) to process errors from task execution.\n\n- **Thread-Safe:**  \n  Built-in synchronization ensures safe concurrent access and modifications.\n\n## Installation\n\nInstall the package using `go get`. Replace `github.com/raykavin/goschd` with your actual module path.\n\n```bash\ngo get github.com/raykavin/goschd\n```\n\n## Usage\n\nImport the package into your project:\n\n```go\nimport \"github.com/raykavin/goschd\"\n```\n\n## Scheduling a Simple Task\n\nThe following example demonstrates scheduling a task that prints a message every second.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/raykavin/goschd\"\n)\n\nfunc main() {\n\tscheduler := goschd.NewTaskScheduler()\n\n\ttask := \u0026goschd.Task{\n\t\tInterval: \"1s\",     // Execute every 1 second\n\t\tRunOnce:  false,    // Recurring task\n\t\tFirstRun: true,     // Execute immediately upon scheduling\n\t\tTaskFunc: func(ctx context.Context) error {\n\t\t\tfmt.Println(\"Simple task executed!\")\n\t\t\treturn nil\n\t\t},\n\t}\n\n\tif err := scheduler.Add(\"simpleTask\", task); err != nil {\n\t\tlog.Fatalf(\"Error adding task: %v\", err)\n\t}\n\n\t// Keep the application running\n\tselect {}\n}\n```\n\n## Scheduling a Cron Task\n\nSchedule a task using a cron expression (with seconds) to fire every 5 seconds.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/raykavin/goschd\"\n)\n\nfunc main() {\n\tscheduler := goschd.NewTaskScheduler()\n\n\tcronTask := \u0026goschd.Task{\n\t\tInterval: \"* * * * * *\", // Cron expression: every second\n\t\tRunOnce:  false,         // Recurring task\n\t\tFirstRun: true,          // Execute immediately upon scheduling\n\t\tTaskFunc: func(ctx context.Context) error {\n\t\t\tfmt.Println(\"Cron task executed!\")\n\t\t\treturn nil\n\t\t},\n\t}\n\n\tif err := scheduler.Add(\"cronTask\", cronTask); err != nil {\n\t\tlog.Fatalf(\"Error adding cron task: %v\", err)\n\t}\n\n\tselect {}\n}\n```\n\n## Delayed Start Task\n\nSchedule a task to start after a specific delay using `StartAfter`.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/raykavin/goschd\"\n)\n\nfunc main() {\n\tscheduler := goschd.NewTaskScheduler()\n\n\tdelayedTask := \u0026goschd.Task{\n\t\tInterval:   \"2s\",                           // Task repeats every 2 seconds\n\t\tRunOnce:    false,                          // Recurring task\n\t\tFirstRun:   false,                          // Do not run immediately\n\t\tStartAfter: time.Now().Add(5 * time.Second),  // Delay start by 5 seconds\n\t\tTaskFunc: func(ctx context.Context) error {\n\t\t\tfmt.Println(\"Delayed task executed!\")\n\t\t\treturn nil\n\t\t},\n\t}\n\n\tif err := scheduler.Add(\"delayedTask\", delayedTask); err != nil {\n\t\tlog.Fatalf(\"Error adding delayed task: %v\", err)\n\t}\n\n\tselect {}\n}\n```\n\n## Error Handling\n\nHandle errors produced by a task using a custom error callback.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/raykavin/goschd\"\n)\n\nfunc main() {\n\tscheduler := schdulerext.NewTaskScheduler()\n\n\terrorTask := \u0026goschd.Task{\n\t\tInterval: \"1s\",    // Execute every 1 second\n\t\tRunOnce:  true,    // Run only once\n\t\tFirstRun: true,    // Execute immediately\n\t\tTaskFunc: func(ctx context.Context) error {\n\t\t\treturn fmt.Errorf(\"simulated error\")\n\t\t},\n\t\tErrFunc: func(err error) {\n\t\t\tfmt.Printf(\"Error handler invoked: %v\\n\", err)\n\t\t},\n\t}\n\n\tif err := scheduler.Add(\"errorTask\", errorTask); err != nil {\n\t\tlog.Fatalf(\"Error adding error task: %v\", err)\n\t}\n\n\ttime.Sleep(1500 * time.Millisecond)\n}\n```\n\n## Testing\n\nThe package includes a suite of tests covering task scheduling, error handling, cloning, and more. To run the tests, use:\n\n```bash\ngo test -v\n```\n\n## 🤝 Contributing\n\nContributions to GoSchd are welcome! Here are some ways you can help improve the project:\n\n- **Report bugs and suggest features** by opening issues on GitHub\n- **Submit pull requests** with bug fixes or new features\n- **Improve documentation** to help other users and developers\n- **Share your custom strategies** with the community\n\n## 📄 License\n\nGoSchd is distributed under the **GNU General Public License v3.0**.  \nFor complete license terms and conditions, see the [LICENSE](LICENSE.md) file in the repository.\n\nCopyright © [Raykavin Meireles](https://github.com/raykavin)\n\n---\n\n## 📬 Contact\n\nFor support, collaboration, or questions about GoSchd:\n\n**Email**: [raykavin.meireles@gmail.com](mailto:raykavin.meireles@gmail.com)  \n**GitHub**: [@raykavin](https://github.com/raykavin)  \n**LinkedIn**: [@raykavin.dev](https://www.linkedin.com/in/raykavin-dev)  \n**Instagram**: [@raykavin.dev](https://www.instagram.com/raykavin.dev)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraykavin%2Fgoschd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraykavin%2Fgoschd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraykavin%2Fgoschd/lists"}