From 506eb22be0ab030b6b4ce6ffe28c41c757cee108 Mon Sep 17 00:00:00 2001 From: stepmr Date: Fri, 11 Dec 2015 17:56:54 -0800 Subject: [PATCH] Support opbeat logging with celery - support opbeat logging with celery - modify sentry imports to avoid conflicts --- .../taskapp/celery.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/taskapp/celery.py b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/taskapp/celery.py index 30fda6eae7..fd324e3163 100644 --- a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/taskapp/celery.py +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/taskapp/celery.py @@ -27,10 +27,27 @@ def ready(self): {% if cookiecutter.use_sentry == "y" -%} if hasattr(settings, 'RAVEN_CONFIG'): # Celery signal registration - from raven import Client - from raven.contrib.celery import register_signal - client = Client(dsn=settings.RAVEN_CONFIG['DSN']) - register_signal(client) + from raven import Client as RavenClient + from raven.contrib.celery import register_signal as raven_register_signal + + raven_client = RavenClient(dsn=settings.RAVEN_CONFIG['DSN']) + raven_register_signal(raven_client) + {%- endif %} + + {% if cookiecutter.use_opbeat == "y" -%} + if hasattr(settings, 'OPBEAT'): + from opbeat.contrib.django.models import client as opbeat_client + from opbeat.contrib.django.models import logger as opbeat_logger + from opbeat.contrib.django.models import register_handlers as opbeat_register_handlers + from opbeat.contrib.celery import register_signal as opbeat_register_signal + + try: + opbeat_register_signal(opbeat_client) + except Exception as e: + opbeat_logger.exception('Failed installing celery hook: %s' % e) + + if 'opbeat.contrib.django' in settings.INSTALLED_APPS: + opbeat_register_handlers() {%- endif %}