You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/11/04 20:27:22 UTC

[GitHub] [airflow] baxievski commented on a change in pull request #12096: add xcom push for ECSOperator

baxievski commented on a change in pull request #12096:
URL: https://github.com/apache/airflow/pull/12096#discussion_r517611582



##########
File path: airflow/providers/amazon/aws/operators/ecs.py
##########
@@ -260,6 +265,24 @@ def _wait_for_task_ended(self) -> None:
         waiter.config.max_attempts = sys.maxsize  # timeout is managed by airflow
         waiter.wait(cluster=self.cluster, tasks=[self.arn])
 
+    def _cloudwatch_log_events(self):
+        if not self.awslogs_group:
+            return
+
+        if not self.awslogs_stream_prefix:
+            return
+
+        task_id = self.arn.split("/")[-1]
+        stream_name = "{}/{}".format(self.awslogs_stream_prefix, task_id)
+
+        return self.get_logs_hook().get_log_events(self.awslogs_group, stream_name)
+
+    def _last_log_event(self):
+        log_events = self._cloudwatch_log_events()
+        if log_events is not None:
+            return deque(log_events, maxlen=1).pop()["message"]

Review comment:
       It's a more efficient way to get the last item from a generator - no need to iterate over every item from the generator just to get to the last one.
   
   It might make a difference in case of lots of events.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org