From 581f75acceb7f6d07725a5d58a705bdd73d0e6ad Mon Sep 17 00:00:00 2001 From: KlochkovHF Date: Thu, 26 Oct 2023 16:10:35 +0300 Subject: [PATCH 1/4] Add async run method --- yatq/worker/cli.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/yatq/worker/cli.py b/yatq/worker/cli.py index 85e7440..ad381e6 100644 --- a/yatq/worker/cli.py +++ b/yatq/worker/cli.py @@ -44,7 +44,7 @@ def run_worker_cli(): # pragma: no cover ) -def run( +async def async_run( worker_settings: Type[WorkerSettings], queue_names: List[str], logging_config: Optional[Dict] = None, @@ -55,9 +55,9 @@ def run( loop = asyncio.get_event_loop() - loop.run_until_complete(worker_settings.on_startup()) + await worker_settings.on_startup() try: - redis_client = loop.run_until_complete(worker_settings.redis_client()) + redis_client = await worker_settings.redis_client() worker = build_worker( redis_client, worker_settings.factory_cls, @@ -72,6 +72,24 @@ def run( for signum in stop_signals: loop.add_signal_handler(signum, lambda: asyncio.create_task(worker.stop())) - loop.run_until_complete(worker.run()) + await worker.run() finally: - loop.run_until_complete(worker_settings.on_shutdown()) + await worker_settings.on_shutdown() + + +def run( + worker_settings: Type[WorkerSettings], + queue_names: List[str], + logging_config: Optional[Dict] = None, + max_jobs: Optional[int] = None, +) -> None: # pragma: no cover + + loop = asyncio.get_event_loop() + loop.run_until_complete( + async_run( + worker_settings=worker_settings, + queue_names=queue_names, + logging_config=logging_config, + max_jobs=max_jobs + ), + ) From f349ce4e1e690848af4810cd47b688b4d18454e4 Mon Sep 17 00:00:00 2001 From: KlochkovHF Date: Thu, 26 Oct 2023 16:13:12 +0300 Subject: [PATCH 2/4] Update project version --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 3094ad1..23390c4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = yatq -version = 0.0.6 +version = 0.0.7 [options] packages = find: From 891340332e8ec13a1848bfdcb68390d146d4ec88 Mon Sep 17 00:00:00 2001 From: KlochkovHF Date: Thu, 26 Oct 2023 16:19:03 +0300 Subject: [PATCH 3/4] codestyle --- yatq/worker/cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yatq/worker/cli.py b/yatq/worker/cli.py index ad381e6..ad7b481 100644 --- a/yatq/worker/cli.py +++ b/yatq/worker/cli.py @@ -83,13 +83,12 @@ def run( logging_config: Optional[Dict] = None, max_jobs: Optional[int] = None, ) -> None: # pragma: no cover - loop = asyncio.get_event_loop() loop.run_until_complete( async_run( worker_settings=worker_settings, queue_names=queue_names, logging_config=logging_config, - max_jobs=max_jobs + max_jobs=max_jobs, ), ) From 5a8719e94f203a6e26db97ea100a0d018eb5c175 Mon Sep 17 00:00:00 2001 From: KlochkovHF Date: Thu, 26 Oct 2023 16:21:44 +0300 Subject: [PATCH 4/4] Add async_run to yatq.init --- yatq/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yatq/__init__.py b/yatq/__init__.py index 3365f33..5323bd7 100644 --- a/yatq/__init__.py +++ b/yatq/__init__.py @@ -1 +1 @@ -from .worker.cli import run +from .worker.cli import run, async_run