airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [airflow] nuclearpinguin commented on a change in pull request #6317: [AIRFLOW-5644] Simplify TriggerDagRunOperator usage
Date Fri, 18 Oct 2019 14:11:45 GMT
nuclearpinguin commented on a change in pull request #6317: [AIRFLOW-5644] Simplify TriggerDagRunOperator
usage
URL: https://github.com/apache/airflow/pull/6317#discussion_r336508465
 
 

 ##########
 File path: airflow/example_dags/example_trigger_target_dag.py
 ##########
 @@ -18,65 +18,36 @@
 # under the License.
 
 """
-This example illustrates the use of the TriggerDagRunOperator. There are 2
-entities at work in this scenario:
-1. The Controller DAG - the DAG that conditionally executes the trigger
-   (in example_trigger_controller.py)
-2. The Target DAG - DAG being triggered
-
-This example illustrates the following features :
-1. A TriggerDagRunOperator that takes:
-  a. A python callable that decides whether or not to trigger the Target DAG
-  b. An optional params dict passed to the python callable to help in
-     evaluating whether or not to trigger the Target DAG
-  c. The id (name) of the Target DAG
-  d. The python callable can add contextual info to the DagRun created by
-     way of adding a Pickleable payload (e.g. dictionary of primitives). This
-     state is then made available to the TargetDag
-2. A Target DAG : c.f. example_trigger_target_dag.py
+Example usage of the TriggerDagRunOperator. This example holds 2 DAGs:
+1. 1st DAG (example_trigger_controller_dag) holds a TriggerDagRunOperator, which will trigger
the 2nd DAG
+2. 2nd DAG (example_trigger_target_dag) which will be triggered by the TriggerDagRunOperator
in the 1st DAG
 """
 
-import pprint
-
-import airflow
+import airflow.utils.dates
 from airflow.models import DAG
 from airflow.operators.bash_operator import BashOperator
 from airflow.operators.python_operator import PythonOperator
 
-pp = pprint.PrettyPrinter(indent=4)
-
-args = {
-    'start_date': airflow.utils.dates.days_ago(2),
-    'owner': 'Airflow',
-}
-
 dag = DAG(
-    dag_id='example_trigger_target_dag',
-    default_args=args,
+    dag_id="example_trigger_target_dag",
+    default_args={"start_date": airflow.utils.dates.days_ago(2), "owner": "Airflow"},
     schedule_interval=None,
 )
 
 
-def run_this_func(**kwargs):
+def run_this_func(**context):
     """
     Print the payload "message" passed to the DagRun conf attribute.
 
     :param dict kwargs: Context
     """
-    print("Remotely received value of {} for key=message".
-          format(kwargs['dag_run'].conf['message']))
+    print("Remotely received value of {} for key=message".format(context["dag_run"].conf["message"]))
 
 
-run_this = PythonOperator(
-    task_id='run_this',
-    python_callable=run_this_func,
-    dag=dag,
-)
+run_this = PythonOperator(task_id="run_this", python_callable=run_this_func, dag=dag)
 
-# You can also access the DagRun object in templates
 bash_task = BashOperator(
     task_id="bash_task",
-    bash_command='echo "Here is the message: '
-                 '{{ dag_run.conf["message"] if dag_run else "" }}" ',
+    bash_command='echo "Here is the message: ' '{{ dag_run.conf["message"] if dag_run else
"" }}" ',
 
 Review comment:
   ```suggestion
       bash_command='echo "Here is the message: '{{ dag_run.conf["message"] if dag_run else
"" }}'" ',
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message