Beispiel #1
0
def failure_callback(context):
    """
    The function that will be executed on failure.

    :param context: The context of the executed task.
    """
    message = (f"AIRFLOW TASK FAILURE TIPS:\n"
               f"DAG:    {context['task_instance'].dag_id}\n"
               f"TASKS:  {context['task_instance'].task_id}\n"
               f"Reason: {context['exception']}\n")
    return DingdingOperator(
        task_id='dingding_success_callback',
        message_type='text',
        message=message,
        at_all=True,
    ).execute(context)
    def test_execute(self, mock_hook):
        operator = DingdingOperator(task_id='dingding_task', dag=self.dag, **self._config)

        self.assertIsNotNone(operator)
        self.assertEqual(self._config['dingding_conn_id'], operator.dingding_conn_id)
        self.assertEqual(self._config['message_type'], operator.message_type)
        self.assertEqual(self._config['message'], operator.message)
        self.assertEqual(self._config['at_mobiles'], operator.at_mobiles)
        self.assertEqual(self._config['at_all'], operator.at_all)

        operator.execute(None)
        mock_hook.assert_called_once_with(
            self._config['dingding_conn_id'],
            self._config['message_type'],
            self._config['message'],
            self._config['at_mobiles'],
            self._config['at_all'],
        )
        mock_hook.return_value.send.assert_called_once_with()
Beispiel #3
0
def failure_callback(context):
    """
    The function that will be executed on failure.

    :param context: The context of the executed task.
    :type context: dict
    """
    message = ('AIRFLOW TASK FAILURE TIPS:\n'
               'DAG:    {}\n'
               'TASKS:  {}\n'
               'Reason: {}\n'.format(context['task_instance'].dag_id,
                                     context['task_instance'].task_id,
                                     context['exception']))
    return DingdingOperator(
        task_id='dingding_success_callback',
        message_type='text',
        message=message,
        at_all=True,
    ).execute(context)
Beispiel #4
0
    def test_execute(self, mock_hook):
        operator = DingdingOperator(task_id='dingding_task', dag=self.dag, **self._config)

        assert operator is not None
        assert self._config['dingding_conn_id'] == operator.dingding_conn_id
        assert self._config['message_type'] == operator.message_type
        assert self._config['message'] == operator.message
        assert self._config['at_mobiles'] == operator.at_mobiles
        assert self._config['at_all'] == operator.at_all

        operator.execute(None)
        mock_hook.assert_called_once_with(
            self._config['dingding_conn_id'],
            self._config['message_type'],
            self._config['message'],
            self._config['at_mobiles'],
            self._config['at_all'],
        )
        mock_hook.return_value.send.assert_called_once_with()
Beispiel #5
0
# [END howto_operator_dingding_failure_callback]

with DAG(
    dag_id='example_dingding_operator',
    default_args=args,
    schedule_interval='@once',
    dagrun_timeout=timedelta(minutes=60),
    start_date=days_ago(2),
    tags=['example'],
) as dag:

    # [START howto_operator_dingding]
    text_msg_remind_none = DingdingOperator(
        task_id='text_msg_remind_none',
        dingding_conn_id='dingding_default',
        message_type='text',
        message='Airflow dingding text message remind none',
        at_mobiles=None,
        at_all=False,
    )
    # [END howto_operator_dingding]

    text_msg_remind_specific = DingdingOperator(
        task_id='text_msg_remind_specific',
        dingding_conn_id='dingding_default',
        message_type='text',
        message='Airflow dingding text message remind specific users',
        at_mobiles=['156XXXXXXXX', '130XXXXXXXX'],
        at_all=False,
    )

    text_msg_remind_include_invalid = DingdingOperator(