{"id":24280797,"url":"https://github.com/daichitakahashi/workerctl","last_synced_at":"2025-07-20T06:04:20.964Z","repository":{"id":43822426,"uuid":"362983056","full_name":"daichitakahashi/workerctl","owner":"daichitakahashi","description":"worker controller for graceful shutdown","archived":false,"fork":false,"pushed_at":"2022-03-01T02:18:44.000Z","size":74,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T00:27:28.270Z","etag":null,"topics":["concurrency","context","go","golang","goroutine","graceful-shutdown"],"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/daichitakahashi.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}},"created_at":"2021-04-30T00:31:24.000Z","updated_at":"2025-03-15T23:21:13.000Z","dependencies_parsed_at":"2022-07-20T19:19:12.664Z","dependency_job_id":null,"html_url":"https://github.com/daichitakahashi/workerctl","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/daichitakahashi/workerctl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daichitakahashi%2Fworkerctl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daichitakahashi%2Fworkerctl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daichitakahashi%2Fworkerctl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daichitakahashi%2Fworkerctl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daichitakahashi","download_url":"https://codeload.github.com/daichitakahashi/workerctl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daichitakahashi%2Fworkerctl/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266076035,"owners_count":23872729,"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":["concurrency","context","go","golang","goroutine","graceful-shutdown"],"created_at":"2025-01-16T02:34:40.872Z","updated_at":"2025-07-20T06:04:20.926Z","avatar_url":"https://github.com/daichitakahashi.png","language":"Go","readme":"# workerctl: worker controller for graceful shutdown\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/daichitakahashi/workerctl.svg)](https://pkg.go.dev/github.com/daichitakahashi/workerctl)\n\nPackage workerctl is controller of application's initialization and its graceful shutdown.\n\n## Usage\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n\t\"time\"\n\n\t\"github.com/daichitakahashi/workerctl\"\n)\n\nfunc main() {\n\tctx := context.Background()\n\ta := \u0026workerctl.Aborter{}\n\tctl, shutdown := workerctl.New()\n\n\ta.AbortOnError(func() (err error) {\n\t\t// 1. Init shared resource and bind to this Controller.\n\t\t// logOutput is used in both OneShotTaskRunner and Server.\n\t\tlogOutput, err := os.CreateTemp(\"\", \"*log\")\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tctl.Bind(logOutput)\n\n\t\t// 2. Start OneShotTaskRunner.\n\t\toneShot := \u0026OneShotTaskRunner{\n\t\t\tWriter: logOutput,\n\t\t}\n\t\terr = ctl.Launch(ctx, oneShot)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t{\n\t\t\t// 3. Create Controller depends on ctl and start Server.\n\t\t\tctl := ctl.Dependent()\n\n\t\t\tserver := \u0026Server{\n\t\t\t\tOneShot: oneShot,\n\t\t\t\tWriter:  logOutput,\n\t\t\t}\n\t\t\terr := ctl.Launch(ctx, server)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}())\n\n\tquit := make(chan os.Signal, 1)\n\tsignal.Notify(quit, syscall.SIGINT)\n\n\t// Once SIGINT received or \"/abort\" requested, Controller starts shutdown.\n\t// First, Server's graceful shutdown finished(3).\n\t// Second, OneShotTaskRunner shutdown after all running task finished(2).\n\t// Finally, logOutput will be closed(1).\n\tselect {\n\tcase \u003c-a.Aborted():\n\t\tlog.Println(\"aborted\")\n\tcase s := \u003c-quit:\n\t\tlog.Println(\"signal received:\", s)\n\t}\n\n\tctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)\n\tdefer cancel()\n\tif err := shutdown(ctx); err != nil {\n\t\tlog.Fatal(\"Server forced to shutdown:\", err)\n\t}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaichitakahashi%2Fworkerctl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaichitakahashi%2Fworkerctl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaichitakahashi%2Fworkerctl/lists"}