From 895e24727d025b87008a591087219aeff90b1ed6 Mon Sep 17 00:00:00 2001 From: Arwichok Date: Sat, 7 Sep 2019 09:36:04 +0300 Subject: [PATCH] Added new on_ registrator for use as decorator when register on_startup, on_shutdown: on_startup_polling, on_startup_webhook, on_shutdown_polling, on_shutdown_webhook --- aiogram/utils/executor.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/aiogram/utils/executor.py b/aiogram/utils/executor.py index 33f80684..0692b68a 100644 --- a/aiogram/utils/executor.py +++ b/aiogram/utils/executor.py @@ -186,6 +186,22 @@ class Executor: if webhook: self._on_startup_webhook.append(callback) + def on_startup_polling(self, callback: callable): + """ + Register a callback for the startup with polling + + :param callback: + """ + self.on_startup(callback, webhook=False) + + def on_startup_webhook(self, callback: callable): + """ + Register a callback for the startup with webhook + + :param callback: + """ + self.on_startup(callback, polling=False) + def on_shutdown(self, callback: callable, polling=True, webhook=True): """ Register a callback for the shutdown process @@ -209,6 +225,22 @@ class Executor: if webhook: self._on_shutdown_webhook.append(callback) + def on_shutdown_polling(self, callback: callable): + """ + Register a callback for the shutdown with pollign + + :param callback: + """ + self.on_shutdown(callback, webhook=False) + + def on_shutdown_webhook(self, callback: callable): + """ + Register a callback for the shutdown with webhook + + :param callback: + """ + self.on_shutdown(callback, polling=False) + def _check_frozen(self): if self.frozen: raise RuntimeError('Executor is frozen!')