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 19:45:16 UTC

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

XD-DENG commented on a change in pull request #12096:
URL: https://github.com/apache/airflow/pull/12096#discussion_r517589217



##########
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:
       May you please clarify why `deque` is needed here? Thanks.

##########
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)

Review comment:
       We have started to enforce using f-string, and this `.format()` usage should fail the CI.




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