

@app.task(ignore_result=True)
def send_notifications(notification_id):
    try:
        notification = ScheduledNotification.objects.get(id=notification_id)
        if (notification.notifier == UserNotificationMethod.METHOD_XMPP):
            notifier = XmppNotifier(settings.XMPP_SETTINGS)
        if (notification.notifier == UserNotificationMethod.METHOD_EMAIL):
            notifier = EmailNotifier(settings.EMAIL_SETTINGS)
        if (notification.notifier == UserNotificationMethod.METHOD_TWILIO_SMS):
            notifier = TwilioSmsNotifier(settings.TWILIO_SETTINGS)
        if (notification.notifier == UserNotificationMethod.METHOD_TWILIO_CALL):
            notifier = TwilioCallNotifier(settings.TWILIO_SETTINGS)
        if (notification.notifier == UserNotificationMethod.METHOD_SLACK):
            notifier = SlackNotifier(settings.SLACK_SETTINGS)
        elif (notification.notifier == UserNotificationMethod.METHOD_PUSHOVER):
            notifier = PushoverNotifier()
        elif (notification.notifier == UserNotificationMethod.METHOD_PROWL):
            notifier = ProwlNotifier(settings.PROWL_SETTINGS)
        notifier.notify(notification)
        logmessage = EventLog()
        if notification.incident:
            logmessage.service_key = notification.incident.service_key
            logmessage.incident_key = notification.incident
            logmessage.user = notification.user_to_notify
            logmessage.action = 'notified'
            logmessage.data = ('Notification sent to %s about %s service' % (notification.user_to_notify, logmessage.service_key))
            logmessage.occurred_at = timezone.now()
            logmessage.save()
        if (notification.notifier != UserNotificationMethod.METHOD_TWILIO_CALL):
            notification.delete()
    except ScheduledNotification.DoesNotExist:
        pass
    except:
        logmessage = EventLog()
        if notification.incident:
            logmessage.service_key = notification.incident.service_key
            logmessage.incident_key = notification.incident
            logmessage.user = notification.user_to_notify
            logmessage.action = 'notification_failed'
            logmessage.data = ('Sending notification failed to %s about %s service' % (notification.user_to_notify, logmessage.service_key))
            logmessage.occurred_at = timezone.now()
            logmessage.save()
        raise

dataset/ETHPy150Open ustream/openduty/notification/tasks.py send_notifications/original