dabla commented on code in PR #62922: URL: https://github.com/apache/airflow/pull/62922#discussion_r2891518885
########## task-sdk/src/airflow/sdk/execution_time/executor.py: ########## @@ -0,0 +1,141 @@ +# +# 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. +from __future__ import annotations + +import asyncio +import contextvars +import inspect +import os +from asyncio import AbstractEventLoop, Semaphore +from collections.abc import Callable +from concurrent.futures import Future, ThreadPoolExecutor, as_completed +from logging import Logger +from typing import TYPE_CHECKING, Any + +from airflow.sdk import BaseAsyncOperator, BaseOperator +from airflow.sdk.bases.operator import ExecutorSafeguard +from airflow.sdk.execution_time.callback_runner import create_executable_runner +from airflow.sdk.execution_time.context import ( + context_get_outlet_events, + context_to_airflow_vars, +) +from airflow.sdk.execution_time.task_runner import ( + RuntimeTaskInstance, + _run_task_state_change_callbacks, +) + +if TYPE_CHECKING: + from airflow.sdk import Context + + +def collect_futures(loop: AbstractEventLoop, futures: list[Any]): + """Yield futures as they complete (sync or async).""" + yield from as_completed(f for f in futures if isinstance(f, Future)) + + async_tasks = [f for f in futures if isinstance(f, asyncio.Task)] + + if async_tasks: + for task, _ in zip( + async_tasks, + loop.run_until_complete(asyncio.gather(*async_tasks, return_exceptions=True)), + ): + yield task + + return [] + Review Comment: I've refactor this a changed the assignation once just before using the `HybridExecutor`. -- 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]
