anishgirianish commented on code in PR #62343: URL: https://github.com/apache/airflow/pull/62343#discussion_r3302016094
########## task-sdk/src/airflow/sdk/execution_time/connection_test_supervisor.py: ########## @@ -0,0 +1,87 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Supervised execution of TestConnection workloads.""" + +from __future__ import annotations + +import uuid + +import structlog + +from airflow.sdk.api.client import Client +from airflow.sdk.api.datamodels._generated import ConnectionTestState +from airflow.sdk.definitions.connection import Connection as SDKConnection +from airflow.sdk.exceptions import AirflowTaskTimeout +from airflow.sdk.execution_time.timeout import TimeoutPosix + +__all__ = ["supervise_connection_test"] + +log = structlog.get_logger(logger_name="connection_test_supervisor") + + +def supervise_connection_test( + *, + connection_test_id: uuid.UUID, + connection_id: str, + timeout: int, + token: str, + server: str, +) -> int: + """Execute a connection test on the worker and report the result via the Execution API.""" + client = Client(base_url=server, token=token) + + try: + r = client.connection_tests.get_connection(connection_test_id) + + conn = SDKConnection( + conn_id=r.conn_id, + conn_type=r.conn_type, + host=r.host, + login=r.login, + password=r.password, + schema=r.schema_, + port=r.port, + extra=r.extra, + ) + with TimeoutPosix( Review Comment: Updated 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]
