Cloned DMOJ
This commit is contained in:
parent
f623974b58
commit
49dc9ff10c
513 changed files with 132349 additions and 39 deletions
27
dmoj/celery.py
Normal file
27
dmoj/celery.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import logging
|
||||
import socket
|
||||
|
||||
from celery import Celery
|
||||
from celery.signals import task_failure
|
||||
|
||||
app = Celery('dmoj')
|
||||
|
||||
from django.conf import settings # noqa: E402, I202, django must be imported here
|
||||
app.config_from_object(settings, namespace='CELERY')
|
||||
|
||||
if hasattr(settings, 'CELERY_BROKER_URL_SECRET'):
|
||||
app.conf.broker_url = settings.CELERY_BROKER_URL_SECRET
|
||||
if hasattr(settings, 'CELERY_RESULT_BACKEND_SECRET'):
|
||||
app.conf.result_backend = settings.CELERY_RESULT_BACKEND_SECRET
|
||||
|
||||
# Load task modules from all registered Django app configs.
|
||||
app.autodiscover_tasks()
|
||||
|
||||
# Logger to enable errors be reported.
|
||||
logger = logging.getLogger('judge.celery')
|
||||
|
||||
|
||||
@task_failure.connect()
|
||||
def celery_failure_log(sender, task_id, exception, traceback, *args, **kwargs):
|
||||
logger.error('Celery Task %s: %s on %s', sender.name, task_id, socket.gethostname(), # noqa: G201
|
||||
exc_info=(type(exception), exception, traceback))
|
Loading…
Add table
Add a link
Reference in a new issue