зеркало из https://github.com/mozilla/MozDef.git
Dynamically register alert tasks in new celery
This commit is contained in:
Родитель
26877426c0
Коммит
baa69f68aa
|
@ -1,4 +1,5 @@
|
|||
from celery import Celery
|
||||
from importlib import import_module
|
||||
from lib.config import ALERTS, LOGGING, RABBITMQ
|
||||
from logging.config import dictConfig
|
||||
|
||||
|
@ -54,5 +55,15 @@ app = Celery('alerts',
|
|||
include=alerts_include)
|
||||
app.config_from_object('celeryconfig', force=True)
|
||||
|
||||
# As a result of celery 3 to celery 4, we need to dynamically
|
||||
# register all of the alert tasks specifically
|
||||
for alert_namespace in CELERYBEAT_SCHEDULE:
|
||||
alert_tokens = alert_namespace.split('.')
|
||||
alert_module_name = alert_tokens[0]
|
||||
alert_classname = alert_tokens[1]
|
||||
alert_module = import_module(alert_module_name)
|
||||
alert_class = getattr(alert_module, alert_classname)
|
||||
app.register_task(alert_class())
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.start()
|
||||
|
|
Загрузка…
Ссылка в новой задаче