{"id":15297454,"url":"https://github.com/sardok/aiogear","last_synced_at":"2025-04-13T23:16:19.749Z","repository":{"id":57408856,"uuid":"79317899","full_name":"sardok/aiogear","owner":"sardok","description":"Asynchronous gearman library based on asyncio","archived":false,"fork":false,"pushed_at":"2018-08-22T17:40:57.000Z","size":44,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T23:15:52.277Z","etag":null,"topics":["asynchronous","asyncio","gearman","python-3"],"latest_commit_sha":null,"homepage":"","language":"Python","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/sardok.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":"2017-01-18T08:10:36.000Z","updated_at":"2023-09-19T07:44:36.000Z","dependencies_parsed_at":"2022-09-26T16:31:21.877Z","dependency_job_id":null,"html_url":"https://github.com/sardok/aiogear","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sardok%2Faiogear","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sardok%2Faiogear/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sardok%2Faiogear/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sardok%2Faiogear/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sardok","download_url":"https://codeload.github.com/sardok/aiogear/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248794568,"owners_count":21162615,"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":["asynchronous","asyncio","gearman","python-3"],"created_at":"2024-09-30T19:17:44.253Z","updated_at":"2025-04-13T23:16:19.725Z","avatar_url":"https://github.com/sardok.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aiogear\nAsynchronous gearman library based on asyncio implemented in pure python.\n\n\n## Asynchonous Worker\n\n### Function Registration as Worker\n\n#### Static Registration\n\nOnce the worker gets connected to the gearman daemon, it registers all the given functions. In the example below, the only registered function is `sleep`.\n\n```python\nasync def sleep(job_info):\n    sleep_time = int(job_info.workload)\n    print(job_info)\n    print('Sleeping for ', sleep_time, ' seconds')\n    await asyncio.sleep(sleep_time)\n    print('Sleep is done')\n\n\nasync def connect_worker(loop, addr, port):\n    factory = lambda: Worker(sleep, loop=loop)\n    _, worker = await loop.create_connection(factory, addr, port)\n    return worker\n```\n#### Dynamic Registration\n\nWhen necessary, registration on runtime (with optional custom name) is possible too.\n\n```python\nworker.register_function(_sleep, 'sleep')\n```\n\n### Registered Function Calls\n\nEach function assigned to a particular job must accept a sole argument `JobInfo`. It is a custom data structure which represents the job. E.g.:\n\n```python\nJobInfo(handle='H:ev-ubuntu:38', function='sleep', uuid=None, reducer=None, workload='5')\n```\n\nIf needed, partial functions could be used for extra argument(s). The function, passed to `Worker` could be `(function, function_name)` pair.\n\n```python\nasync def sleep(loop, job_info):\n    pass\n\nasync def connect_worker(loop, addr, port):\n    func = functools.partial(sleep, loop)\n    factory = lambda: Worker((func, 'sleep'), loop=loop)\n    _, worker = await loop.create_connection(factory, addr, port)\n    return worker\n```\n\nFor running more than one worker in parallel see `examples/` directory.\n\n\n## Asynchonous Client\n\nCreating client is as simple as creating tcp client.\n\n```python\nasync def connect(loop, addr, port):\n    client = Client()\n    await loop.create_connection(lambda: client, addr, port)\n    return client\n```\n\nSubmitted job returns custom data structure `JobCreated` with a `handle` property which could be used to trace the job.\n\n```python\njob_created = await client.submit_job('sleep', '5')\nprint(job_created) # JobCreated(handle='H:ev-ubuntu:38')\n```\n\n`asyncio.Future` returning `wait_job` method could be used to asynchronously block the current context until job is finished.\n\n```python\ndef job_is_complete(job_created, f):\n    print('Created Job ', job_created, ' is finished')\n\nf = client.wait_job(job_created.handle)\nf.add_done_callback(partial(job_is_complete, job_created))\nawait f\n```\n\n\nFor more and complete examples, please see `examples/` directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsardok%2Faiogear","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsardok%2Faiogear","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsardok%2Faiogear/lists"}