|
@@ -7,7 +7,7 @@ import socket
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
from carrot.connection import DjangoBrokerConnection
|
|
|
-from carrot.messaging import Publisher, Consumer, ConsumerSet
|
|
|
+from carrot.messaging import Publisher, Consumer, ConsumerSet as _ConsumerSet
|
|
|
from billiard.utils.functional import wraps
|
|
|
|
|
|
from celery import conf
|
|
@@ -75,6 +75,35 @@ class TaskPublisher(Publisher):
|
|
|
return task_id
|
|
|
|
|
|
|
|
|
+class ConsumerSet(_ConsumerSet):
|
|
|
+ """ConsumerSet with an optional decode error callback.
|
|
|
+
|
|
|
+ For more information see :class:`carrot.messaging.ConsumerSet`.
|
|
|
+
|
|
|
+ .. attribute:: on_decode_error
|
|
|
+
|
|
|
+ Callback called if a message had decoding errors.
|
|
|
+ The callback is called with the signature::
|
|
|
+
|
|
|
+ callback(message, exception)
|
|
|
+
|
|
|
+ """
|
|
|
+ on_decode_error = None
|
|
|
+
|
|
|
+ def _receive_callback(self, raw_message):
|
|
|
+ message = self.backend.message_to_python(raw_message)
|
|
|
+ if self.auto_ack and not message.acknowledged:
|
|
|
+ message.ack()
|
|
|
+ try:
|
|
|
+ decoded = message.decode()
|
|
|
+ except Exception, exc:
|
|
|
+ if self.on_decode_error:
|
|
|
+ return self.on_decode_error(message, exc)
|
|
|
+ else:
|
|
|
+ raise
|
|
|
+ self.receive(decoded, message)
|
|
|
+
|
|
|
+
|
|
|
class TaskConsumer(Consumer):
|
|
|
"""Consume tasks"""
|
|
|
queue = conf.DEFAULT_QUEUE
|