Exemple #1
0
    def notify(self, old_task_state, new_task_state):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)
        event = events.identify_task_event(old_task_state, new_task_state)

        def _convert_to_notification_data():
            return {
                "id": self.task_ex.id,
                "name": self.task_ex.name,
                "workflow_name": self.task_ex.workflow_name,
                "workflow_namespace": self.task_ex.workflow_namespace,
                "workflow_id": self.task_ex.workflow_id,
                "state": self.task_ex.state,
                "state_info": self.task_ex.state_info,
                "type": self.task_ex.type,
                "project_id": self.task_ex.project_id
            }

        def _send_notification():
            notifier.notify(self.task_ex.id, _convert_to_notification_data(),
                            event, self.task_ex.updated_at, publishers)

        post_tx_queue.register_operation(_send_notification)
Exemple #2
0
    def notify(self, event):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        notifier.notify(self.wf_ex.id, self.wf_ex.to_dict(), event,
                        self.wf_ex.updated_at, publishers)
Exemple #3
0
    def notify(self, old_task_state, new_task_state):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)
        event = events.identify_task_event(old_task_state, new_task_state)

        notifier.notify(self.task_ex.id, self.task_ex.to_dict(), event,
                        self.task_ex.updated_at, publishers)
Exemple #4
0
    def notify(self, event):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        notifier.notify(
            self.wf_ex.id,
            self.wf_ex.to_dict(),
            event,
            self.wf_ex.updated_at,
            publishers
        )
Exemple #5
0
    def notify(self, old_task_state, new_task_state):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)
        event = events.identify_task_event(old_task_state, new_task_state)

        notifier.notify(
            self.task_ex.id,
            self.task_ex.to_dict(),
            event,
            self.task_ex.updated_at,
            publishers
        )
Exemple #6
0
    def _notify(self, from_state, to_state):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        event = events.identify_task_event(from_state, to_state)

        filtered_publishers = []

        for publisher in publishers:
            if not isinstance(publisher, dict):
                continue

            target_events = publisher.get('event_types', [])

            if not target_events or event in target_events:
                filtered_publishers.append(publisher)

        if not filtered_publishers:
            return

        data = {
            "id": self.task_ex.id,
            "name": self.task_ex.name,
            "workflow_execution_id": self.task_ex.workflow_execution_id,
            "workflow_name": self.task_ex.workflow_name,
            "workflow_namespace": self.task_ex.workflow_namespace,
            "workflow_id": self.task_ex.workflow_id,
            "state": self.task_ex.state,
            "state_info": self.task_ex.state_info,
            "type": self.task_ex.type,
            "project_id": self.task_ex.project_id,
            "created_at": utils.datetime_to_str(self.task_ex.created_at),
            "updated_at": utils.datetime_to_str(self.task_ex.updated_at),
            "started_at": utils.datetime_to_str(self.task_ex.started_at),
            "finished_at": utils.datetime_to_str(self.task_ex.finished_at)
        }

        def _send_notification():
            notifier.notify(self.task_ex.id, data, event,
                            self.task_ex.updated_at, filtered_publishers)

        post_tx_queue.register_operation(_send_notification)
Exemple #7
0
    def notify(self, event):
        publishers = self.wf_ex.params.get('notify')

        if not publishers and not isinstance(publishers, list):
            return

        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        filtered_publishers = []

        for publisher in publishers:
            if not isinstance(publisher, dict):
                continue

            target_events = publisher.get('event_types', [])

            if not target_events or event in target_events:
                filtered_publishers.append(publisher)

        if not filtered_publishers:
            return

        def _convert_to_notification_data():
            return {
                "id": self.wf_ex.id,
                "name": self.wf_ex.name,
                "workflow_name": self.wf_ex.workflow_name,
                "workflow_namespace": self.wf_ex.workflow_namespace,
                "workflow_id": self.wf_ex.workflow_id,
                "state": self.wf_ex.state,
                "state_info": self.wf_ex.state_info,
                "project_id": self.wf_ex.project_id,
                "task_execution_id": self.wf_ex.task_execution_id
            }

        def _send_notification():
            notifier.notify(
                self.wf_ex.id,
                _convert_to_notification_data(),
                event,
                self.wf_ex.updated_at,
                filtered_publishers
            )

        post_tx_queue.register_operation(_send_notification)
Exemple #8
0
    def test_get_notifier(self):
        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        self.assertEqual('local', cfg.CONF.notifier.type)
        self.assertIsInstance(notifier, d_notif.DefaultNotifier)
Exemple #9
0
    def test_get_notifier(self):
        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        self.assertEqual('remote', cfg.CONF.notifier.type)
        self.assertIsInstance(notifier, r_notif.RemoteNotifier)
    def test_get_notifier(self):
        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        self.assertEqual('local', cfg.CONF.notifier.type)
        self.assertIsInstance(notifier, d_notif.DefaultNotifier)
    def test_get_notifier(self):
        notifier = notif.get_notifier(cfg.CONF.notifier.type)

        self.assertEqual('remote', cfg.CONF.notifier.type)
        self.assertIsInstance(notifier, r_notif.RemoteNotifier)