Support both celery _send task and non-celery _send method
@@ -6,12 +6,22 @@ logger = logging.getLogger(__name__)
class SenderBase(object):
+ def __init__(self):
+ # In case some of our sender plugins are not using celery,
+ # We store our calling function in self.__send so that send()
+ # and test() can call the correct function while leaving the
+ # original function alone in case it needs to be called directly
+ if hasattr(self._send, 'delay'):
+ self.__send = self._send.delay
+ else:
+ self.__send = self._send
+
def send(self, data):
sent = 0
for alert in data['alerts']:
project = alert['labels'].get('project')
for sender in Sender.objects.filter(sender=self.__module__, project__name=project):
- if self._send.delay(sender.value, alert, data):
+ if self.__send(sender.value, alert, data):
logger.debug('Sent %s for %s', self.__module__, project)
sent += 1
if sent == 0:
@@ -20,4 +30,4 @@ class SenderBase(object):
def test(self, target, alert):
logger.debug('Sending test message to %s', target)
- self._send.delay(target, alert, {'externalURL': ''})
+ self.__send(target, alert, {'externalURL': ''})
