{"id":19600913,"url":"https://github.com/iq-tech/go-jobs","last_synced_at":"2026-06-12T08:32:21.975Z","repository":{"id":45322416,"uuid":"438025027","full_name":"IQ-tech/go-jobs","owner":"IQ-tech","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-21T13:12:25.000Z","size":5,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-01-09T08:17:18.757Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IQ-tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-13T21:07:06.000Z","updated_at":"2021-12-21T13:09:00.000Z","dependencies_parsed_at":"2022-09-01T20:24:01.929Z","dependency_job_id":null,"html_url":"https://github.com/IQ-tech/go-jobs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IQ-tech%2Fgo-jobs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IQ-tech%2Fgo-jobs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IQ-tech%2Fgo-jobs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IQ-tech%2Fgo-jobs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IQ-tech","download_url":"https://codeload.github.com/IQ-tech/go-jobs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240879279,"owners_count":19872331,"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-11T09:16:34.298Z","updated_at":"2026-06-12T08:32:21.945Z","avatar_url":"https://github.com/IQ-tech.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bounded job execution with in memory queue\n\nRun jobs with controlled concurrency.\n\n# Installation\n\nTo install, use `go get`\n\n```terminal\ngo get github.com/IQ-tech/go-jobs\n```\n\n# Usage\n\n## Creating a new dispatcher\n\nCreating a dispatcher that will run 2 concurrent jobs and queue 5 jobs.\n\n```go\ndispatcher := jobs.NewDispatcher(2, 5)\n```\n\n## Running jobs\n\n`Run` enqueues a job to that will be picked up by one of the workers.  \n`Run` will block if the queue is full.\n\n```go\ndispatcher := jobs.NewDispatcher(2, 1)\n\n// Does not block because a worker picks the job from\n// the queue immediately after we add the job to it.\n//\n// We have 2 workers and 1 is busy now.\ndispatcher.Run(func() {\n  time.Sleep(10 * time.Second)\n})\n\n\n// Does not block because a worker picks the job from\n// the queue immediately after we add the job to it.\n//\n// We have 2 workers and both are busy now.\ndispatcher.Run(func() {\n  time.Sleep(10 * time.Second)\n})\n\n// Does not block because even though both workers are busy,\n// we have a queue that can have at most one job in it.\ndispatcher.Run(func() {\n  time.Sleep(10 * time.Second)\n})\n\n// Blocks because both workers are busy and the queue is full.\ndispatcher.Run(func() {\n  time.Sleep(10 * time.Second)\n})\n```\n\n## Testing\n\nAsynchronicity makes testing more annoying, because of that we have the `Sync`  \nmethod to make testing easier.\n\nCalling `Sync` will change the dispatcher to sync mode(default is async)  \nwhich makes the dispatcher execute jobs synchronously instead of enqueuing them.\n\n```go\npackage package_test\n\nfunc Test_Sync(t*testing.T){\n  t.Parallel()\n\t// We dont need workers or a queue if we are running in sync mode\n\tdispatcher := NewDispatcher(0, 0)\n\n\tdispatcher.Sync()\n\n\tran := false\n\tdispatcher.Run(func() {\n\t\tran = true\n\t})\n\n  assert.True(t, ran)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiq-tech%2Fgo-jobs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiq-tech%2Fgo-jobs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiq-tech%2Fgo-jobs/lists"}