Ejemplo n.º 1
0
    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()
    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()
def failure_callback(context):
    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',
        dingding_conn_id='dingding_default',
        message_type='text',
        message=message,
        at_all=True,
    ).execute(context)
Ejemplo n.º 4
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',
        dingding_conn_id='dingding_default',
        message_type='text',
        message=message,
        at_all=True,
    ).execute(context)
Ejemplo n.º 5
0
    ).execute(context)


args['on_failure_callback'] = failure_callback
# [END howto_operator_dingding_failure_callback]

with DAG(dag_id='example_dingding_operator',
         default_args=args,
         schedule_interval='@once',
         dagrun_timeout=timedelta(minutes=60)) 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(
        task_id='text_msg_remind_include_invalid',
Ejemplo n.º 6
0
from datetime import datetime,timedelta

import airflow
from airflow.contrib.operators.dingding_operator import DingdingOperator
from airflow.models import DAG

args = {
        'owner': 'anitha',
        'start_date':datetime(2018,8,11),
        }

dag = DAG(
    dag_id='dingding_example',
    default_args=args,
    schedule_interval='@once',
    dagrun_timeout=timedelta(minutes=60),
)

text_msg_remind_all = DingdingOperator(
    task_id='text_msg_remind_all',
    dingding_conn_id='anitha_ding',
    message_type='text',
    message='Airflow dingding text message remind all users in group',
    # list of user phone/email here in the group
    # when at_all is specific will cover at_mobiles
    at_mobiles=['9994692674'],
    at_all=True,
    dag=dag,
)