ashb commented on code in PR #44899: URL: https://github.com/apache/airflow/pull/44899#discussion_r1886936844
########## airflow/api_fastapi/execution_api/routes/task_instances.py: ########## @@ -48,6 +51,108 @@ log = logging.getLogger(__name__) [email protected]( + "/{task_instance_id}/run", + status_code=status.HTTP_200_OK, + responses={ + status.HTTP_404_NOT_FOUND: {"description": "Task Instance not found"}, + status.HTTP_409_CONFLICT: {"description": "The TI is already in the requested state"}, + status.HTTP_422_UNPROCESSABLE_ENTITY: {"description": "Invalid payload for the state transition"}, + }, +) +def ti_run( + task_instance_id: UUID, ti_run_payload: Annotated[TIEnterRunningPayload, Body()], session: SessionDep +) -> TIRunContext: + """ + Run a TaskInstance. + + This endpoint is used to start a TaskInstance that is in the QUEUED state. + """ + # We only use UUID above for validation purposes + ti_id_str = str(task_instance_id) + + old = select(TI.state, TI.dag_id, TI.run_id).where(TI.id == ti_id_str).with_for_update() + try: + (previous_state, dag_id, run_id) = session.execute(old).one() + except NoResultFound: + log.error("Task Instance %s not found", ti_id_str) + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail={ + "reason": "not_found", + "message": "Task Instance not found", + }, + ) + + # We exclude_unset to avoid updating fields that are not set in the payload + data = ti_run_payload.model_dump(exclude_unset=True) + + query = update(TI).where(TI.id == ti_id_str).values(data) + + if previous_state != State.QUEUED: Review Comment: @amoghrajesh The question is does the scheduler change the state to queued for those two states before it can get to a worker (My gut says yes, the scheduler does this) -- 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]
