You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/06/02 10:56:21 UTC

[GitHub] [airflow] fbertos edited a comment on issue #15888: Abort a DAG Run

fbertos edited a comment on issue #15888:
URL: https://github.com/apache/airflow/issues/15888#issuecomment-852925274


   Hi @alexing,
   
   We tried a different approach through the REST API to avoid touching the DB, this a code example:
   
   
   ```
       run_id = str(sys.argv[2])
   
       # We get first the task instance of the DAG run
       r = requests.get('http://localhost:8081/api/v1/dags/' + dag_id + '/dagRuns/' + str(run_id) + '/taskInstances?state=running', 
           auth=HTTPBasicAuth('admin', 'admin'))
   
       print(r.json()['task_instances'][0])
       task_id = r.json()['task_instances'][0]['task_id']
       execution_date = r.json()['task_instances'][0]['execution_date']
   
       # We set the tasks to failed
       r = requests.post('http://localhost:8081/api/v1/dags/' + dag_id + '/updateTaskInstancesState', 
           json={"dry_run": False,
               "task_id": str(task_id), 
               "execution_date": str(execution_date),
               "include_upstream": False,
               "include_downstream": False,
               "include_future": False,
               "include_past": False,
               "new_state": "**failed**" 
           },
           auth=HTTPBasicAuth('admin', 'admin'))
   
       if r.status_code == 200:
           print("Dag aborted")
   
   ```
   
   I hope it helps.
   


-- 
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