ChristianYeah commented on issue #9209:
URL: https://github.com/apache/airflow/issues/9209#issuecomment-648032574


   > can we explain the requirement with clear example?
   
   ```
   import airflow
   from airflow import DAG
   from airflow.operators.python_operator import PythonOperator
   import requests
   
   
   default_args = {
       'owner': 'airflow',
   }
   
   dag = DAG(
       dag_id='test_max_active_runs',
       default_args=default_args,
       schedule_interval=None,
       start_date=airflow.utils.dates.days_ago(1),
       max_active_runs=1,
       catchup=False
   )
   
   
   def example_func():
       data = requests.get("some url").json()
       if data.get('code', -1) == 0:
           #  no error in the response
           #  further process
           #  eg.
           print(data.get('results', []))
       else:
           #  error in response
           print(data.get('message', ''))
           # mark the task as failed here
           # something like below
           fail_this_task()
   
   
   example = PythonOperator(
       task_id='example',
       python_callable=example_func,
       dag=dag,
   )
   
   ```
   
   is that possible I can fail the task dynamically if I get the response of 
"code" except 0?
   
   @barmanand , thank you very much


----------------------------------------------------------------
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:
[email protected]


Reply via email to