def slack_failed_notification(context):
    """
    Define the callback to post on Slack if a failure is detected in the Workflow
    set on 'on_failure_callback'
    """
    operator = SlackAPIPostOperator(task_id='slack_failed_notification',
                                    text=str(context['task_instance']) + '\n' +
                                    'exception: ' + str(context['exception']),
                                    token=Variable.get("slack_access_token"),
                                    channel='#channel_name')
    return operator.execute(context=context)
Esempio n. 2
0
    def test_api_call_params_with_default_args(self, mock_hook):
        test_slack_conn_id = 'test_slack_conn_id'

        slack_api_post_operator = SlackAPIPostOperator(
            task_id='slack',
            username=self.test_username,
            slack_conn_id=test_slack_conn_id,
        )

        slack_api_post_operator.execute()

        expected_api_params = {
            'channel': "#general",
            'username': self.test_username,
            'text': 'No message has been set.\n'
            'Here is a cat video instead\n'
            'https://www.youtube.com/watch?v=J---aiyznGQ',
            'icon_url': "https://raw.githubusercontent.com/apache/"
            "airflow/master/airflow/www/static/pin_100.png",
            'attachments': '[]',
            'blocks': '[]',
        }
        assert expected_api_params == slack_api_post_operator.api_params