Skip to content

Commit

Permalink
refactor: add startup/shutdown methods to SilverbackApp
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Nov 13, 2023
1 parent 254dd83 commit df0e0d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion silverback/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def __init__(self, settings: Optional[Settings] = None):
f"{signer_str}{start_block_str}{new_block_timeout_str}"
)

async def startup(self):
await self.broker.startup()

def on_startup(self) -> Callable:
"""
Code to execute on worker startup / restart after an error.
Expand All @@ -85,6 +88,9 @@ def do_something_on_startup(state):
"""
return self.broker.on_event(TaskiqEvents.WORKER_STARTUP)

async def shutdown(self):
await self.broker.shutdown()

def on_shutdown(self) -> Callable:
"""
Code to execute on normal worker shutdown.
Expand Down Expand Up @@ -126,7 +132,7 @@ def on_(
container: Union[BlockContainer, ContractEvent],
new_block_timeout: Optional[int] = None,
start_block: Optional[int] = None,
):
) -> AsyncTaskiqDecoratedTask:
"""
Create task to handle events created by `container`.
Expand Down
4 changes: 2 additions & 2 deletions silverback/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def run(self):
Raises:
:class:`~silverback.exceptions.Halt`: If there are no configured tasks to execute.
"""
await self.app.broker.startup()
await self.app.startup()

if block_handler := self.app.get_block_handler():
tasks = [self._block_task(block_handler)]
Expand All @@ -72,7 +72,7 @@ async def run(self):

await asyncio.gather(*tasks)

await self.app.broker.shutdown()
await self.app.shutdown()


class WebsocketRunner(BaseRunner, ManagerAccessMixin):
Expand Down

0 comments on commit df0e0d4

Please sign in to comment.