示例#1
0
    def test_call_backend(self):
        """
        Test messaging call_backend task.
        """
        from_user = _create_user('Bob')
        to_user = _create_user('Alice')
        instance = _create_message(from_user, to_user, 'I love oov')

        with self.assertRaises(NotImplementedError):
            call_backend('onadata.apps.messaging.backends.base.BaseBackend',
                         instance.id, {'HOST': 'localhost'})
示例#2
0
    def test_call_backend(self):
        """
        Test messaging call_backend task.
        """
        from_user = _create_user('Bob')
        to_user = _create_user('Alice')
        instance = _create_message(from_user, to_user, 'I love oov')

        with self.assertRaises(NotImplementedError):
            call_backend('onadata.apps.messaging.backends.base.BaseBackend',
                         instance.id, {'HOST': 'localhost'})
示例#3
0
def messaging_backends_handler(sender, **kwargs):  # pylint: disable=W0613
    """
    Handler to send messages to notification backends e.g MQTT.
    """
    backends = getattr(settings, 'NOTIFICATION_BACKENDS', {})
    as_task = getattr(settings, 'MESSAGING_ASYNC_NOTIFICATION', False)
    created = kwargs.get('created')
    instance = kwargs.get('instance')
    if instance and created:
        for name in backends:
            backend = backends[name]['BACKEND']
            backend_options = backends[name].get('OPTIONS')
            if as_task:
                call_backend_async.delay(backend, instance.id, backend_options)
            else:
                call_backend(backend, instance.id, backend_options)
示例#4
0
def messaging_backends_handler(sender, **kwargs):  # pylint: disable=W0613
    """
    Handler to send messages to notification backends e.g MQTT.
    """
    backends = getattr(settings, 'NOTIFICATION_BACKENDS', {})
    as_task = getattr(settings, 'MESSAGING_ASYNC_NOTIFICATION', False)
    created = kwargs.get('created')
    instance = kwargs.get('instance')
    if instance and created:
        for name in backends:
            backend = backends[name]['BACKEND']
            backend_options = backends[name].get('OPTIONS')
            if as_task:
                # Sometimes the Action isn't created yet, hence
                # the need to delay 2 seconds
                call_backend_async.apply_async(
                    (backend, instance.id, backend_options), countdown=2)
            else:
                call_backend(backend, instance.id, backend_options)
示例#5
0
def call_backend_async(backend, instance_id, backend_options=None):
    """
    Task to send messages to notification backeds such as MQTT
    """
    call_backend(backend, instance_id, backend_options)