anishgirianish commented on code in PR #62343:
URL: https://github.com/apache/airflow/pull/62343#discussion_r2842160078
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py:
##########
@@ -249,6 +277,99 @@ def test_connection(test_body: ConnectionBody) ->
ConnectionTestResponse:
os.environ.pop(conn_env_var, None)
+@connections_router.post(
+ "/test-async",
+ status_code=status.HTTP_202_ACCEPTED,
+ responses=create_openapi_http_exception_doc([status.HTTP_403_FORBIDDEN,
status.HTTP_404_NOT_FOUND]),
+ dependencies=[Depends(requires_access_connection(method="POST")),
Depends(action_logging())],
+)
+def test_connection_async(
+ test_body: ConnectionTestRequestBody,
+ session: SessionDep,
+) -> ConnectionTestQueuedResponse:
+ """
+ Queue an async connection test to be executed on a worker.
+
+ The connection must already be saved. Returns a token that can be used
+ to poll for the test result via GET /connections/test-async/{token}.
+ """
+ if conf.get("core", "test_connection",
fallback="Disabled").lower().strip() != "enabled":
+ raise HTTPException(
+ status.HTTP_403_FORBIDDEN,
+ "Testing connections is disabled in Airflow configuration. "
+ "Contact your deployment admin to enable it.",
+ )
+
+ try:
+ Connection.get_connection_from_secrets(test_body.connection_id)
+ except AirflowNotFoundException:
+ raise HTTPException(
+ status.HTTP_404_NOT_FOUND,
+ f"The Connection with connection_id: `{test_body.connection_id}`
was not found. "
+ "Connection must be saved before testing.",
+ )
+
+ connection_test = ConnectionTest(connection_id=test_body.connection_id)
+ session.add(connection_test)
+ session.flush()
+
+ # ExecutorCallback requires an object satisfying
ImportPathExecutorCallbackDefProtocol,
+ # but the only concrete impl (SyncCallback) lives in task-sdk which core
API cannot
+ # import. This adapter will be replaced by ExecuteCallback.make() once
#61153 merges.
+ callback_def = _ImportPathCallbackDef(
+ path=RUN_CONNECTION_TEST_PATH,
+ kwargs={
+ "connection_id": test_body.connection_id,
+ "connection_test_id": str(connection_test.id),
+ },
+ )
+ callback = ExecutorCallback(callback_def,
fetch_method=CallbackFetchMethod.IMPORT_PATH)
Review Comment:
moved it to connection_test.py and added a create_callback() factory method
on the model. The route now just calls connection_test.create_callback(). Much
cleaner, thank you!
--
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]