ferruzzi commented on code in PR #36803:
URL: https://github.com/apache/airflow/pull/36803#discussion_r1462634293


##########
airflow/providers/amazon/aws/executors/ecs/ecs_executor.py:
##########
@@ -470,3 +481,43 @@ def get_container(self, container_list):
             if container["name"] == self.container_name:
                 return container
         raise KeyError(f"No such container found by container name: 
{self.container_name}")
+
+    def try_adopt_task_instances(self, tis: Sequence[TaskInstance]) -> 
Sequence[TaskInstance]:
+        """
+        Try to adopt running task instances if adopt_task_instances option is 
set to True.
+
+        These tasks instances should have an ECS process which can be adopted 
by the unique task ARN.
+        Anything that is not adopted will be cleared by the scheduler and 
becomes eligible for re-scheduling.
+        """
+        if not self.adopt_task_instances:
+            # Do not try to adopt task instances, return all orphaned tasks 
for clearing
+            return tis
+
+        adopted_tis: list[TaskInstance] = []
+
+        if task_arns := [ti.external_executor_id for ti in tis if 
ti.external_executor_id]:
+            task_descriptions = self.__describe_tasks(task_arns).get("tasks", 
[])
+
+            for task in task_descriptions:
+                ti = [ti for ti in tis if ti.external_executor_id == 
task.task_arn][0]
+                self.active_workers.add_task(
+                    task,
+                    ti.key,
+                    ti.queue,
+                    ti.command_as_list(),
+                    ti.executor_config,
+                    ti.prev_attempted_tries + 1,

Review Comment:
   @o-nikolas thoughts on this one?



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