Lee-W commented on code in PR #52868: URL: https://github.com/apache/airflow/pull/52868#discussion_r2193905930
########## providers/standard/src/airflow/providers/standard/operators/hitl.py: ########## @@ -0,0 +1,206 @@ +# 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 airflow.exceptions import AirflowOptionalProviderFeatureException +from airflow.providers.standard.version_compat import AIRFLOW_V_3_1_PLUS + +if not AIRFLOW_V_3_1_PLUS: + raise AirflowOptionalProviderFeatureException("Human in the loop functionality needs Airflow 3.1+.") + + +from collections.abc import Collection, Mapping +from datetime import datetime, timezone +from typing import TYPE_CHECKING, Any + +from airflow.models import SkipMixin +from airflow.models.baseoperator import BaseOperator +from airflow.providers.standard.exceptions import HITLTriggerEventError +from airflow.providers.standard.triggers.hitl import HITLTrigger, HITLTriggerEventSuccessPayload +from airflow.sdk.definitions.param import ParamsDict +from airflow.sdk.execution_time.hitl import add_hitl_response + +if TYPE_CHECKING: + from airflow.sdk.definitions.context import Context + + +class HITLOperator(BaseOperator): + """ + Base class for all Human-in-the-loop Operators to inherit from. + + :param subject: Headline/subject presented to the user for the interaction task. + :param options: List of options that the an user can select from to complete the task. + :param body: descriptive text that might give background, hints or can provide background or summary of + details that are needed to decide. + :param default: The default option and the option that is taken if timeout is passed. + :param multiple: Whether the user can select one or multiple options. + :param params: dictionary of parameter definitions that are in the format of Dag params such that + a Form Field can be rendered. Entered data is validated (schema, required fields) like for a Dag run + and added to XCom of the task result. + """ + + template_fields: Collection[str] = ("subject", "body") + + def __init__( + self, + *, + subject: str, + options: list[str], + body: str | None = None, + default: str | list[str] | None = None, + multiple: bool = False, + params: ParamsDict | dict[str, Any] | None = None, + **kwargs, + ) -> None: + super().__init__(**kwargs) + self.subject = subject + self.body = body + + self.options = options + # allow defaults to store more than one options when multiple=True + self.default = [default] if isinstance(default, str) else default + self.multiple = multiple + + self.params: ParamsDict | dict = params or {} Review Comment: ah... right... will address it! -- 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]
