Skip to content

Commit 9004b02

Browse files
committed
Added shutdown and startup events.
Signed-off-by: Pavel Kirilin <[email protected]>
1 parent 7db2e2f commit 9004b02

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

taskiq/abc/broker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ def __init__(
147147
self.is_worker_process = False
148148
self._related_tasks: Set[AsyncTaskiqDecoratedTask[..., Any]] = set()
149149

150-
def close(self) -> None:
150+
async def startup(self) -> None:
151+
"""Do something when starting broker."""
152+
153+
async def shutdown(self) -> None:
151154
"""
152155
Close the broker.
153156

taskiq/abc/result_backend.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def value(self) -> Any:
4444
class AsyncResultBackend(ABC, Generic[_ReturnType]):
4545
"""Async result backend."""
4646

47+
async def startup(self) -> None:
48+
"""Do something when starting broker."""
49+
50+
async def shutdown(self) -> None:
51+
"""Do something on shutdown."""
52+
4753
def generate_task(self, task_id: str) -> "AsyncTaskiqTask[_ReturnType]":
4854
"""
4955
Generates new task.

taskiq/cli/task_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ async def async_listen_messages( # noqa: C901, WPS210
169169
:param broker: broker to listen to.
170170
:param cli_args: CLI arguments for worker.
171171
"""
172+
logger.info("Runing startup event.")
173+
await broker.startup()
172174
logger.info("Listening started.")
173175
task_registry: Dict[str, Callable[..., Any]] = {}
174176
task_signatures: Dict[str, inspect.Signature] = {}

0 commit comments

Comments
 (0)