ashb commented on code in PR #43076: URL: https://github.com/apache/airflow/pull/43076#discussion_r1816572620
########## task_sdk/src/airflow/sdk/definitions/abstractoperator.py: ########## @@ -0,0 +1,267 @@ +# +# 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 datetime +from abc import abstractmethod +from collections.abc import ( + Collection, + Iterable, +) +from typing import ( + TYPE_CHECKING, + Any, + ClassVar, +) + +from airflow.sdk.definitions.mixins import DependencyMixin +from airflow.sdk.definitions.node import DAGNode +from airflow.utils.trigger_rule import TriggerRule +from airflow.utils.weight_rule import WeightRule + +# TaskStateChangeCallback = Callable[[Context], None] + +if TYPE_CHECKING: + from airflow.models.baseoperatorlink import BaseOperatorLink + from airflow.models.operator import Operator + from airflow.sdk.definitions.baseoperator import BaseOperator + from airflow.sdk.definitions.dag import DAG + + # TODO: Task-SDK + Context = dict[str, Any] + + +DEFAULT_OWNER: str = "airflow" +DEFAULT_POOL_SLOTS: int = 1 +DEFAULT_PRIORITY_WEIGHT: int = 1 +DEFAULT_EXECUTOR: str | None = None +DEFAULT_QUEUE: str = "default" +DEFAULT_IGNORE_FIRST_DEPENDS_ON_PAST: bool = False +DEFAULT_WAIT_FOR_PAST_DEPENDS_BEFORE_SKIPPING: bool = False +DEFAULT_RETRIES: int = 0 +DEFAULT_RETRY_DELAY: datetime.timedelta = datetime.timedelta(seconds=300) +MAX_RETRY_DELAY: int = 24 * 60 * 60 + +# TODO: Task-SDK -- these defaults should be overridable from the Airflow config +DEFAULT_TRIGGER_RULE: TriggerRule = TriggerRule.ALL_SUCCESS +DEFAULT_WEIGHT_RULE: WeightRule = WeightRule.DOWNSTREAM +DEFAULT_TASK_EXECUTION_TIMEOUT: datetime.timedelta | None = None + + +class NotMapped(Exception): + """Raise if a task is neither mapped nor has any parent mapped groups.""" + + +class AbstractOperator(DAGNode): + """ + Common implementation for operators, including unmapped and mapped. + + This base class is more about sharing implementations, not defining a common + interface. Unfortunately it's difficult to use this as the common base class + for typing due to BaseOperator carrying too much historical baggage. + + The union type ``from airflow.models.operator import Operator`` is easier + to use for typing purposes. + + :meta private: + """ + + operator_class: type[BaseOperator] | dict[str, Any] + + priority_weight: int + + # Defines the operator level extra links. + operator_extra_links: Collection[BaseOperatorLink] + + owner: str + task_id: str + + outlets: list + inlets: list + # TODO: + trigger_rule: TriggerRule + _needs_expansion: bool | None = None + _on_failure_fail_dagrun = False + is_setup: bool = False + is_teardown: bool = False + + HIDE_ATTRS_FROM_UI: ClassVar[frozenset[str]] = frozenset( Review Comment: Yeah for sure. Good eye -- 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]
