{"id":19485510,"url":"https://github.com/chapsuk/worker","last_synced_at":"2025-04-25T17:30:34.862Z","repository":{"id":57481569,"uuid":"130341843","full_name":"chapsuk/worker","owner":"chapsuk","description":"Simple abstraction for control background jobs","archived":false,"fork":false,"pushed_at":"2019-09-08T19:30:27.000Z","size":53,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T00:51:12.375Z","etag":null,"topics":[],"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/chapsuk.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":"2018-04-20T09:37:47.000Z","updated_at":"2022-04-28T13:36:14.000Z","dependencies_parsed_at":"2022-09-26T17:50:33.466Z","dependency_job_id":null,"html_url":"https://github.com/chapsuk/worker","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chapsuk%2Fworker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chapsuk%2Fworker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chapsuk%2Fworker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chapsuk%2Fworker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chapsuk","download_url":"https://codeload.github.com/chapsuk/worker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250861916,"owners_count":21499184,"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":[],"created_at":"2024-11-10T20:28:07.722Z","updated_at":"2025-04-25T17:30:34.625Z","avatar_url":"https://github.com/chapsuk.png","language":"Go","readme":"# Worker\n\n[![GoDoc](http://godoc.org/github.com/chapsuk/worker?status.png)](http://godoc.org/github.com/chapsuk/worker)\n[![Build Status](https://travis-ci.org/chapsuk/worker.svg?branch=master)](https://travis-ci.org/chapsuk/worker)\n[![codecov](https://codecov.io/gh/chapsuk/worker/branch/master/graph/badge.svg)](https://codecov.io/gh/chapsuk/worker)\n[![Go Report Card](https://goreportcard.com/badge/github.com/chapsuk/worker?)](https://goreportcard.com/report/github.com/chapsuk/worker)\n[![codebeat badge](https://codebeat.co/badges/3ddfb9a1-9fb9-49b2-ac72-b259822576aa)](https://codebeat.co/projects/github-com-chapsuk-worker-master)\n\nPackage worker adding the abstraction layer around background jobs,\nallows make a job periodically, observe execution time and to control concurrent execution.\n\nGroup of workers allows to control jobs start time and\nwait until all runned workers finished when we need stop all jobs.\n\n## Features\n\n* Scheduling, use one from existing `worker.By*` schedule functions. Supporting cron schedule spec format by [robfig/cron](https://github.com/robfig/cron) parser.\n* Control concurrent execution around multiple instances by `worker.WithLock`. See existing lockers\n* Observe a job execution time duration with `worker.SetObserever`. Friendly for [prometheus/client_golang](https://github.com/prometheus/client_golang/) package.\n* Graceful stop, wait until all running jobs was completed.\n\n## Example\n\n```go\nwg := worker.NewGroup()\nwg.Add(\n    worker.\n        New(func(context.Context) {}).\n        ByTicker(time.Second),\n\n    worker.\n        New(func(context.Context) {}).\n        ByTimer(time.Second),\n\n    worker.\n        New(func(context.Context) {}).\n        ByCronSpec(\"@every 1s\"),\n)\nwg.Run()\n```\n\n## Lockers\n\nYou can use redis locks for controll exclusive job execution:\n\n```go\nl := locker.NewRedis(radix.Client, \"job_lock_name\", locker.RedisLockTTL(time.Minute))\n\nw := worker.\n        New(func(context.Context) {}).\n        WithLock(l)\n\n// Job will be executed only if `job_lock_name` redis key not exists.\nw.Run(context.Background())\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchapsuk%2Fworker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchapsuk%2Fworker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchapsuk%2Fworker/lists"}