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 2022/09/21 14:33:19 UTC
[GitHub] [airflow] bbovenzi commented on a diff in pull request #26528: Dagrun run taskinstance api
bbovenzi commented on code in PR #26528:
URL: https://github.com/apache/airflow/pull/26528#discussion_r976580072
##########
airflow/api_connexion/endpoints/task_instance_endpoint.py:
##########
@@ -545,3 +550,86 @@ def post_set_task_instances_state(*, dag_id: str, session: Session = NEW_SESSION
session=session,
)
return task_instance_reference_collection_schema.dump(TaskInstanceReferenceCollection(task_instances=tis))
+
+
+@security.requires_access(
+ [
+ (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
+ (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE),
+ ],
+)
+@provide_session
+def run_task_instance(
+ *, dag_id: str, dag_run_id: str, task_id: str, session: Session = NEW_SESSION
+) -> APIResponse:
+ """Run a task instance."""
+ body = request.get_json()
Review Comment:
```suggestion
body = get_json_request_dict()
```
##########
airflow/api_connexion/endpoints/task_instance_endpoint.py:
##########
@@ -545,3 +550,86 @@ def post_set_task_instances_state(*, dag_id: str, session: Session = NEW_SESSION
session=session,
)
return task_instance_reference_collection_schema.dump(TaskInstanceReferenceCollection(task_instances=tis))
+
+
+@security.requires_access(
+ [
+ (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG),
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
+ (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_TASK_INSTANCE),
+ ],
+)
+@provide_session
+def run_task_instance(
+ *, dag_id: str, dag_run_id: str, task_id: str, session: Session = NEW_SESSION
+) -> APIResponse:
+ """Run a task instance."""
+ body = request.get_json()
+ try:
+ data = run_task_instance_form.load(body)
+ except ValidationError as err:
+ raise BadRequest(detail=str(err.messages))
+
+ ignore_all_deps = data.get('ignore_all_deps')
+ ignore_task_deps = data.get('ignore_task_deps')
+ ignore_ti_state = data.get('ignore_ti_state')
+ map_index = data.get('map_index')
+
+ executor = ExecutorLoader.get_default_executor()
+ if not getattr(executor, "supports_ad_hoc_ti_run", False):
+ error_message = "Only works with the Celery, CeleryKubernetes or Kubernetes executors"
+ raise BadRequest(detail=error_message)
+
+ error_message = f"Dag ID {dag_id} not found"
+ dag = current_app.dag_bag.get_dag(dag_id)
Review Comment:
```suggestion
dag = get_airflow_app().dag_bag.get_dag(dag_id)
```
--
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.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org