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:
Arwichok 2019-09-07 09:36:04 +03:00
parent 4984c2313a
commit 895e24727d

View file

@ -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!')