Ariel2400 commented on code in PR #53492: URL: https://github.com/apache/airflow/pull/53492#discussion_r2257911624
########## airflow-core/src/airflow/task/pessimistic_task_selector.py: ########## @@ -0,0 +1,216 @@ +# 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 + +from collections.abc import Collection +from dataclasses import dataclass +from typing import TYPE_CHECKING + +from sqlalchemy import Column, and_, func, select, text +from sqlalchemy.orm import Query, selectinload + +from airflow.models import DagRun, TaskInstance +from airflow.models.dag import DagModel +from airflow.models.pool import Pool +from airflow.task.task_selector_strategy import TaskSelectorStrategy +from airflow.ti_deps.dependencies_states import EXECUTION_STATES +from airflow.utils.state import DagRunState, TaskInstanceState + +if TYPE_CHECKING: + from sqlalchemy.orm import Query + from sqlalchemy.sql import expression + from sqlalchemy.sql.selectable import CTE, Select + + from airflow.models.base import Base + + +@dataclass +class LimitWindowDescriptor: + """ + Describes a limit window. + + Args: + running_now_join (Subquery): the subquery on which we join for the window to get the additional parallelism + limits data. + running_now_join_predicates (Collection[str]): on what columns we do the join for for the + running_now_join, also used in the group by. + limit_column (Column): The column which decides how many rows should be chosen per window for + concurency limits. + window (expression.ColumnElement): the column by which we window. + limit_join_model (Base | None): the model on which we join to get a concurency limit. + """ + + running_now_join: CTE + running_now_join_predicates: Collection[str] + limit_column: Column + window: expression.ColumnElement + limit_join_model: Base | None = None + + +TI = TaskInstance +DR = DagRun +DM = DagModel + + +class PessimisticTaskSelector(TaskSelectorStrategy): + """ + Pessimisticly query task instances ready for scheduling. + + Works by delegating almost all the work from python do sql. Review Comment: also, please run spellchecker on the rest of the docstrings -- 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]
