mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
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
This commit is contained in:
parent
4984c2313a
commit
895e24727d
1 changed files with 32 additions and 0 deletions
|
|
@ -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!')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue