pankajkoti commented on code in PR #30945: URL: https://github.com/apache/airflow/pull/30945#discussion_r1184760151
########## airflow/providers/amazon/aws/triggers/emr.py: ########## @@ -0,0 +1,82 @@ +# 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 Any, AsyncIterator + +from airflow.compat.functools import cached_property +from airflow.providers.amazon.aws.hooks.emr import EmrContainerHook +from airflow.triggers.base import BaseTrigger, TriggerEvent + + +class EmrContainerSensorTrigger(BaseTrigger): + """ + Poll for the status of EMR container until reaches terminal state + + :param virtual_cluster_id: Reference Emr cluster id + :param job_id: job_id to check the state + :param max_tries: maximum try attempts for polling the status + :param aws_conn_id: Reference to AWS connection id + :param poll_interval: polling period in seconds to check for the status + """ + + def __init__( + self, + virtual_cluster_id: str, + job_id: str, + aws_conn_id: str = "aws_default", + poll_interval: int = 10, + max_tries: int | None = None, + **kwargs: Any, + ): + self.virtual_cluster_id = virtual_cluster_id + self.job_id = job_id + self.aws_conn_id = aws_conn_id + self.poll_interval = poll_interval + self.max_tries = max_tries + super().__init__(**kwargs) + + @cached_property + def hook(self) -> EmrContainerHook: + return EmrContainerHook(self.aws_conn_id, virtual_cluster_id=self.virtual_cluster_id) + + def serialize(self) -> tuple[str, dict[str, Any]]: + """Serializes EmrContainerSensorTrigger arguments and classpath.""" + return ( + "airflow.providers.amazon.aws.triggers.emr.EmrContainerSensorTrigger", + { + "virtual_cluster_id": self.virtual_cluster_id, + "job_id": self.job_id, + "aws_conn_id": self.aws_conn_id, + "max_tries": self.max_tries, + "poll_interval": self.poll_interval, + }, + ) + + async def run(self) -> AsyncIterator[TriggerEvent]: + async with self.hook.async_conn as client: Review Comment: I checked the approach there and have added a couple of comments. Please check. -- 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]
