Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airflow/providers/amazon/aws/operators/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ def _try_reattach_task(self, context):
)
if previous_task_arn in running_tasks:
self.arn = previous_task_arn
self.ecs_task_id = self.arn.split("/")[-1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: When I had coded this (before I knew you were working on it 😆) I extracted setting the arn/task_id into a helper method, because this code is now duplicated in two spots. Not a huge deal, since ARNs are fairly stable, but worth considering. Approving

self.log.info("Reattaching previously launched task: %s", self.arn)
else:
self.log.info("No active previously launched task found to reattach")
Expand Down
3 changes: 3 additions & 0 deletions tests/providers/amazon/aws/operators/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def test_execute_without_failures(
wait_mock.assert_called_once_with()
check_mock.assert_called_once_with()
assert self.ecs.arn == 'arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55'
assert self.ecs.ecs_task_id == 'd8c67b3c-ac87-4ffe-a847-4785bc3a8b55'

def test_execute_with_failures(self):
client_mock = self.aws_hook_mock.return_value.get_conn.return_value
Expand Down Expand Up @@ -478,6 +479,7 @@ def test_reattach_successful(
check_mock.assert_called_once_with()
xcom_del_mock.assert_called_once()
assert self.ecs.arn == 'arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55'
assert self.ecs.ecs_task_id == 'd8c67b3c-ac87-4ffe-a847-4785bc3a8b55'

@parameterized.expand(
[
Expand Down Expand Up @@ -526,6 +528,7 @@ def test_reattach_save_task_arn_xcom(
check_mock.assert_called_once_with()
xcom_del_mock.assert_called_once()
assert self.ecs.arn == 'arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55'
assert self.ecs.ecs_task_id == 'd8c67b3c-ac87-4ffe-a847-4785bc3a8b55'

def test_execute_xcom_with_log(self):
self.ecs.do_xcom_push = True
Expand Down