vincbeck commented on code in PR #30463:
URL: https://github.com/apache/airflow/pull/30463#discussion_r1214445808


##########
airflow/providers/amazon/aws/operators/emr.py:
##########
@@ -901,36 +930,63 @@ def execute(self, context: Context) -> str | None:
             raise AirflowException(f"Application Creation failed: {response}")
 
         self.log.info("EMR serverless application created: %s", application_id)
-
-        # This should be replaced with a boto waiter when available.
-        waiter(
-            get_state_callable=self.hook.conn.get_application,
-            get_state_args={"applicationId": application_id},
-            parse_response=["application", "state"],
-            desired_state={"CREATED"},
-            failure_states=EmrServerlessHook.APPLICATION_FAILURE_STATES,
-            object_type="application",
-            action="created",
-            countdown=self.waiter_countdown,
-            check_interval_seconds=self.waiter_check_interval_seconds,
-        )
+        attempt = 0
+        waiter = self.hook.get_waiter("serverless_app_created")
+        while attempt < self.waiter_max_attempts:

Review Comment:
   I see. I have another proposal (yes as you can see I really hate this code). 
Why dont you move this code in a separate function and you use `tenacity` to 
handle the retry. The code would look like this:
   
   ```python
   @tenacity.retry(
       retry=tenacity.retry_if_exception_type(WaiterError),
       stop=tenacity.stop_after_attempt(self.waiter_max_attempts),
       wait=tenacity.wait_fixed(self.waiter_delay),
   )
   def wait(waiter: Waiter, application_id: str):
       try:
           waiter.wait(
               applicationId=application_id,
               WaiterConfig=prune_dict(
                   {
                       "Delay": self.waiter_delay,
                       "MaxAttempts": 1,
                   }
               ),
           )
       except WaiterError as error:
           if "terminal failure" in str(error):
               raise AirflowException(f"Serverless Application Creation failed: 
{error}")
           self.log.info(
               "Serverless Application status is: %s - %s",
               error.last_response["application"]["state"],
               error.last_response["application"]["stateDetails"],
           )
           raise
   ```
   
   I am still not a big fan of this code but this is definitely better than the 
while loop



-- 
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]

Reply via email to