uranusjr commented on code in PR #66848: URL: https://github.com/apache/airflow/pull/66848#discussion_r3401478840
########## airflow-core/src/airflow/partition_mappers/wait_policy.py: ########## @@ -0,0 +1,174 @@ +# 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 typing import TYPE_CHECKING, Any + +import attrs + +if TYPE_CHECKING: + from collections.abc import Set + + [email protected](frozen=True) +class PartitionSatisfaction: + """ + Structured result returned by :meth:`WaitPolicy.is_satisfied_by_keys`. + + :param satisfied: ``True`` if the matched key set meets the policy's firing threshold. + :param unreachable: ``True`` if the policy threshold can never be met given the window's + cardinality, regardless of how many upstream events arrive. + :param unreachable_reason: Human-readable explanation of why the policy is unreachable, + constructed atomically by the policy from its own repr and the window's cardinality. + Non-``None`` if and only if ``unreachable`` is ``True``; the scheduler may forward + this string directly to :meth:`~logging.Logger.warning` without further formatting. + """ + + satisfied: bool + unreachable: bool + unreachable_reason: str | None + + def __attrs_post_init__(self) -> None: + if self.unreachable and self.unreachable_reason is None: + raise ValueError("unreachable_reason must be set when unreachable is True") + if not self.unreachable and self.unreachable_reason is not None: + raise ValueError("unreachable_reason must be None when unreachable is False") + + +class WaitPolicy: + """ + An object the scheduler asks whether a partitioned Dag run should fire. + + Concrete policies are ``WaitForAll`` and ``MinimumCount``. The scheduler + calls only :meth:`is_satisfied_by_keys`, which returns a :class:`PartitionSatisfaction` + carrying both the satisfaction result and the unreachability flag. + :meth:`is_satisfied` and :meth:`is_unreachable` are internal collaboration + points used by policy implementations; they are not called directly by the + scheduler. + + :meta private: + """ + + def is_satisfied(self, matched: int, expected: int) -> bool: + raise NotImplementedError + + def is_satisfied_by_keys(self, *, matched: Set[str], expected: Set[str]) -> PartitionSatisfaction: Review Comment: I just noticed this; shouldn’t `set[str]` work? (And based on ruff being fine with this and not “fixing” it, I assume there is a reason?) -- 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]
