amoghrajesh commented on code in PR #46020:
URL: https://github.com/apache/airflow/pull/46020#discussion_r1931640484


##########
airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -442,6 +444,48 @@ def get_previous_successful_dagrun(
     return PrevSuccessfulDagRunResponse.model_validate(dag_run)
 
 
[email protected](
+    "/{task_instance_id}/runtime-checks",
+    status_code=status.HTTP_200_OK,
+    # TODO: Add description to the operation
+    # TODO: Add Operation ID to control the function name in the OpenAPI spec
+    # TODO: Do we need to use create_openapi_http_exception_doc here?
+    responses={
+        status.HTTP_400_BAD_REQUEST: {
+            "description": "Task Instance doesn't pass the required runtime 
checks"
+        },
+        status.HTTP_204_NO_CONTENT: {
+            "description": "Task Instance is not in a running state, cannot 
perform runtime checks."
+        },
+        status.HTTP_422_UNPROCESSABLE_ENTITY: {
+            "description": "Invalid payload for requested runtime checks on 
the Task Instance."
+        },
+    },
+)
+def ti_runtime_checks(
+    task_instance_id: UUID,
+    payload: TIRuntimeCheckPayload,
+    session: SessionDep,
+):
+    ti_id_str = str(task_instance_id)
+    task_instance = session.scalar(select(TI).where(TI.id == ti_id_str))
+    if task_instance.state != State.RUNNING:
+        return Response(status_code=status.HTTP_204_NO_CONTENT)

Review Comment:
   > Returning a 204 if the task isn't in the right state doesn't feel right. 
This feels more like it should be a HTTP 409 or a 400, and 204 No Content 
should be for the success path
   
   Yeah, that sounds better once you said it.
   204: If the check passes
   409: when the TI isn't in the right state
   400: when the check fails
   



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to