This enables JSON logging for Celery workers if the LOG_JSON conig value is set. It uses the same JsonFormatter class used by the Flask applications. That class has been updated in two ways: - It takes a `source` kwarg to define the log source for the formatter. - The `msg` attribute of the log record is formatted with any arguments that may have been passed. This is necessary for Celery to render task type, completion time, etc. into the log output.
31 lines
823 B
Python
31 lines
823 B
Python
from celery import Celery
|
|
|
|
|
|
celery = Celery(__name__)
|
|
|
|
|
|
def update_celery(celery, app):
|
|
celery.conf.update(app.config)
|
|
celery.conf.CELERYBEAT_SCHEDULE = {
|
|
"beat-dispatch_create_environment": {
|
|
"task": "atst.jobs.dispatch_create_environment",
|
|
"schedule": 60,
|
|
},
|
|
"beat-dispatch_create_atat_admin_user": {
|
|
"task": "atst.jobs.dispatch_create_atat_admin_user",
|
|
"schedule": 60,
|
|
},
|
|
"beat-dispatch_provision_user": {
|
|
"task": "atst.jobs.dispatch_provision_user",
|
|
"schedule": 60,
|
|
},
|
|
}
|
|
|
|
class ContextTask(celery.Task):
|
|
def __call__(self, *args, **kwargs):
|
|
with app.app_context():
|
|
return self.run(*args, **kwargs)
|
|
|
|
celery.Task = ContextTask
|
|
return celery
|