From 97d6c1736377a567051bdf94c942a391475e46e1 Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Thu, 6 Jun 2024 09:48:34 +0100 Subject: [PATCH] Update register events (#57) --- asyncz/contrib/esmerald/scheduler.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/asyncz/contrib/esmerald/scheduler.py b/asyncz/contrib/esmerald/scheduler.py index 394e547..e2fc502 100644 --- a/asyncz/contrib/esmerald/scheduler.py +++ b/asyncz/contrib/esmerald/scheduler.py @@ -18,7 +18,6 @@ if TYPE_CHECKING: from esmerald.applications import Esmerald - from pydantic.typing import AnyCallable class EsmeraldScheduler: @@ -93,14 +92,15 @@ def register_events(self, app: "Esmerald") -> None: """ Registers the scheduler events in the Esmerald application. """ + if app.on_startup is not None: + app.on_startup.append(self.handler.start) + else: + app.on_startup = [self.handler.start] - @app.on_event("startup") - def start_scheduler() -> None: - self.handler.start() - - @app.on_event("shutdown") - def stop_scheduler() -> None: - self.handler.shutdown() + if app.on_shutdown is not None: + app.on_shutdown.append(self.handler.shutdown) + else: + app.on_shutdown = [self.handler.shutdown] def get_scheduler( self, @@ -208,7 +208,7 @@ def add_task(self, scheduler: "SchedulerType"): except Exception as e: raise ImproperlyConfigured(str(e)) from e - def __call__(self, fn: "AnyCallable") -> None: + def __call__(self, fn: Any) -> None: """ Tricking the object into think it's being instantiated by in reality is just returning itself.