fbertos commented 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")
   
   ```


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