ashb commented on code in PR #43076: URL: https://github.com/apache/airflow/pull/43076#discussion_r1804373804
########## task_sdk/src/airflow/sdk/definitions/abstractoperator.py: ########## @@ -0,0 +1,231 @@ +# +# 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.node import DAGNode +from airflow.utils.log.secrets_masker import redact + +# TaskStateChangeCallback = Callable[[Context], None] + +if TYPE_CHECKING: + import jinja2 # Slow import. + + from airflow.models.baseoperatorlink import BaseOperatorLink + from airflow.sdk.definitions.baseoperator import BaseOperator + from airflow.sdk.definitions.dag import DAG + from airflow.task.priority_strategy import PriorityWeightStrategy + + # 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 +# DEFAULT_TRIGGER_RULE: TriggerRule = TriggerRule.ALL_SUCCESS +DEFAULT_TRIGGER_RULE = "all_success" +DEFAULT_WEIGHT_RULE = "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] + + weight_rule: PriorityWeightStrategy + priority_weight: int + + # Defines the operator level extra links. + operator_extra_links: Collection[BaseOperatorLink] Review Comment: Yeah, very soon (along with all the tests etc) -- 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]
