{"id":20261608,"url":"https://github.com/ronelliott/keepalive","last_synced_at":"2025-07-02T00:03:06.340Z","repository":{"id":214431031,"uuid":"736420328","full_name":"ronelliott/keepalive","owner":"ronelliott","description":"Keep goroutines running!","archived":false,"fork":false,"pushed_at":"2023-12-28T04:45:04.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T09:01:49.334Z","etag":null,"topics":["go","golang","goroutine","goroutines"],"latest_commit_sha":null,"homepage":"https://github.com/ronelliott/keepalive","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ronelliott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-27T21:26:39.000Z","updated_at":"2023-12-28T04:47:03.000Z","dependencies_parsed_at":"2023-12-28T06:59:52.754Z","dependency_job_id":null,"html_url":"https://github.com/ronelliott/keepalive","commit_stats":null,"previous_names":["ronelliott/keepalive"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ronelliott/keepalive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronelliott%2Fkeepalive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronelliott%2Fkeepalive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronelliott%2Fkeepalive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronelliott%2Fkeepalive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronelliott","download_url":"https://codeload.github.com/ronelliott/keepalive/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronelliott%2Fkeepalive/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263052431,"owners_count":23406104,"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":["go","golang","goroutine","goroutines"],"created_at":"2024-11-14T11:26:00.894Z","updated_at":"2025-07-02T00:03:06.278Z","avatar_url":"https://github.com/ronelliott.png","language":"Go","readme":"# keepalive\n\n![Build Status](https://github.com/ronelliott/keepalive/actions/workflows/master.yml/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ronelliott/keepalive)](https://goreportcard.com/report/github.com/ronelliott/keepalive)\n[![Coverage Status](https://coveralls.io/repos/github/ronelliott/keepalive/badge.svg?branch=master)](https://coveralls.io/github/ronelliott/keepalive?branch=master)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ronelliott/keepalive.svg)](https://pkg.go.dev/github.com/ronelliott/keepalive)\n\nkeepalive is a lightweight goroutine manager that keeps a goroutine running and restarts it after errors.\n\n## Manager\n\nA manager manages one or more workers. Workers can be registered with an identifier by calling the `AddWorker` method on a manager instance. Once registered, a worker can then be started and stopped using the `StartWorker` and `StopWorker` methods respectively.\n\nIf a worker encounters an error, it will be restarted after a delay that is increased exponentially.\n\n## Worker\n\nWorkers must implement the `Worker` interface, which requires implementing the `Run` and `Stop` methods. When `Run` is called on a worker, it must block until `Stop` is called on that worker. If an error is encountered by a worker during normal operation, it should be returned from the `Run` method.\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/ronelliott/keepalive\"\n)\n\ntype myWorker struct {\n\tstopped bool\n}\n\nfunc (service *myWorker) Run() error {\n\tservice.stopped = false\n\tfor {\n\t\tif service.stopped {\n\t\t\tbreak\n\t\t}\n\n\t\tfmt.Println(\"cycle\")\n\t\ttime.Sleep(time.Second * 5)\n\t}\n\n\treturn nil\n}\n\nfunc (service *myWorker) Stop() error {\n\tservice.stopped = true\n\treturn nil\n}\n\nfunc main() {\n\tmanager := keepalive.NewManager()\n\n\tmanager.AddWorker(\"worker1\", \u0026myWorker{})\n\tmanager.AddWorker(\"worker2\", \u0026myWorker{})\n\n\tmanager.StartWorker(\"worker1\", \"worker2\")\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronelliott%2Fkeepalive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronelliott%2Fkeepalive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronelliott%2Fkeepalive/lists"}