From 2d8b445a4da00fa8fb6628037a4307da5d93301a Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 9 Dec 2013 22:52:10 -0800 Subject: [PATCH] Remove raven.contrib.celery --- docs/config/celery.rst | 10 ------ raven/contrib/celery/__init__.py | 32 +++++------------- raven/contrib/django/celery/__init__.py | 13 ++------ tests/contrib/celery/__init__.py | 0 tests/contrib/celery/tests.py | 44 ------------------------- tests/contrib/django/tests.py | 29 ---------------- 6 files changed, 12 insertions(+), 116 deletions(-) delete mode 100644 docs/config/celery.rst delete mode 100644 tests/contrib/celery/__init__.py delete mode 100644 tests/contrib/celery/tests.py diff --git a/docs/config/celery.rst b/docs/config/celery.rst deleted file mode 100644 index 54af93a07..000000000 --- a/docs/config/celery.rst +++ /dev/null @@ -1,10 +0,0 @@ -Configuring Celery -================== - -Celery provides a hook for catching task failures, and Raven can easily plug into that hook:: - - from raven.contrib.celery import register_signal - - register_signal(client) - -If you're using Django and ``djcelery`` exists in your ``INSTALLED_APPS``, we've already set this up for you. diff --git a/raven/contrib/celery/__init__.py b/raven/contrib/celery/__init__.py index 7faae2bd7..4616151d8 100644 --- a/raven/contrib/celery/__init__.py +++ b/raven/contrib/celery/__init__.py @@ -2,39 +2,25 @@ raven.contrib.celery ~~~~~~~~~~~~~~~~~~~~ +>>> class CeleryClient(CeleryMixin, Client): +>>> def send_encoded(self, *args, **kwargs): +>>> "Errors through celery" +>>> self.send_raw.delay(*args, **kwargs) + +>>> @task(routing_key='sentry') +>>> def send_raw(*args, **kwargs): +>>> return super(client, self).send_encoded(*args, **kwargs) + :copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ from __future__ import absolute_import import logging -try: - from celery.contrib.methods import task -except ImportError: - # Import the pre Celery 3.1 tasks (At some point we'll drop that) - try: - from celery.task import task - except ImportError: - from celery.decorators import task # NOQA from celery.signals import after_setup_logger, task_failure -from raven.base import Client from raven.handlers.logging import SentryHandler -class CeleryMixin(object): - def send_encoded(self, *args, **kwargs): - "Errors through celery" - self.send_raw.delay(*args, **kwargs) - - @task(routing_key='sentry') - def send_raw(self, *args, **kwargs): - return super(CeleryMixin, self).send_encoded(*args, **kwargs) - - -class CeleryClient(CeleryMixin, Client): - pass - - class CeleryFilter(logging.Filter): def filter(self, record): # Context is fixed in Celery 3.x so use internal flag instead diff --git a/raven/contrib/django/celery/__init__.py b/raven/contrib/django/celery/__init__.py index 7aecb8587..d38df731b 100644 --- a/raven/contrib/django/celery/__init__.py +++ b/raven/contrib/django/celery/__init__.py @@ -7,25 +7,18 @@ """ from __future__ import absolute_import -from raven.contrib.celery import CeleryMixin from raven.contrib.django.client import DjangoClient try: - from celery.contrib.methods import task + from celery.task import task except ImportError: - # Import the pre Celery 3.1 tasks (At some point we'll drop that) - try: - from celery.task import task - except ImportError: - from celery.decorators import task # NOQA + from celery.decorators import task # NOQA -class CeleryClient(CeleryMixin, DjangoClient): - +class CeleryClient(DjangoClient): def send_integrated(self, kwargs): return send_raw_integrated.delay(kwargs) def send_encoded(self, *args, **kwargs): - "Errors through celery" return send_raw.delay(*args, **kwargs) diff --git a/tests/contrib/celery/__init__.py b/tests/contrib/celery/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/contrib/celery/tests.py b/tests/contrib/celery/tests.py deleted file mode 100644 index 1666c2f24..000000000 --- a/tests/contrib/celery/tests.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- - -import mock - -from celery.app import app_or_default - -from raven.utils.testutils import TestCase -from raven.contrib.celery import CeleryClient - - -class ClientTest(TestCase): - def setUp(self): - self.client = CeleryClient(servers=['http://example.com']) - - @mock.patch('raven.contrib.celery.CeleryClient.send_raw') - def test_send_encoded(self, send_raw): - self.client.send_encoded('foo') - - send_raw.delay.assert_called_once_with('foo') - - @mock.patch('raven.contrib.celery.CeleryClient.send_raw') - def test_without_eager(self, send_raw): - """ - Integration test to ensure it propagates all the way down - and calls delay on the task. - """ - self.client.captureMessage(message='test') - - self.assertEquals(send_raw.delay.call_count, 1) - - @mock.patch('raven.base.Client.send_encoded') - def test_with_eager(self, send_encoded): - """ - Integration test to ensure it propagates all the way down - and calls the parent client's send_encoded method. - """ - celery_app = app_or_default() - celery_app.conf.CELERY_ALWAYS_EAGER = True - - self.client.captureMessage(message='test') - - self.assertEquals(send_encoded.call_count, 1) - - celery_app.conf.CELERY_ALWAYS_EAGER = False diff --git a/tests/contrib/django/tests.py b/tests/contrib/django/tests.py index 101d074e8..ed1054882 100644 --- a/tests/contrib/django/tests.py +++ b/tests/contrib/django/tests.py @@ -12,7 +12,6 @@ import re import sys # NOQA from exam import fixture -from celery.app import app_or_default from django.conf import settings from django.core.exceptions import SuspiciousOperation @@ -594,20 +593,6 @@ def test_without_eager(self, send_raw): self.assertEquals(send_raw.delay.call_count, 1) - # @with_eager_tasks - @mock.patch('raven.contrib.django.DjangoClient.send_encoded') - def test_with_eager(self, send_encoded): - """ - Integration test to ensure it propagates all the way down - and calls the parent client's send_encoded method. - """ - celery_app = app_or_default() - celery_app.conf.CELERY_ALWAYS_EAGER = True - self.client.captureMessage(message='test') - - self.assertEquals(send_encoded.call_count, 1) - celery_app.conf.CELERY_ALWAYS_EAGER = False - class CeleryIntegratedClientTest(TestCase): def setUp(self): @@ -631,20 +616,6 @@ def test_without_eager(self, send_raw): self.assertEquals(send_raw.delay.call_count, 1) - # @with_eager_tasks - @mock.patch('raven.contrib.django.DjangoClient.send_encoded') - def test_with_eager(self, send_encoded): - """ - Integration test to ensure it propagates all the way down - and calls the parent client's send_encoded method. - """ - celery_app = app_or_default() - celery_app.conf.CELERY_ALWAYS_EAGER = True - self.client.captureMessage(message='test') - - self.assertEquals(send_encoded.call_count, 1) - celery_app.conf.CELERY_ALWAYS_EAGER = False - class IsValidOriginTestCase(TestCase): def test_setting_empty(self):