Skip to content

Commit ca08306

Browse files
committed
Fix deployment rollbacking with more than 100 tasks
The `list_tasks` call was capped at 100 tasks, if your service had a desired superior of 100 the deployment would fail. Fix #174 Signed-off-by: Adrien Fillon <[email protected]>
1 parent 76f9cf0 commit ca08306

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

ecs_deploy/ecs.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import copy
55
from collections import defaultdict
6+
import itertools
67
import logging
78
import click_log
89

@@ -71,10 +72,13 @@ def describe_task_definition(self, task_definition_arn):
7172
)
7273

7374
def list_tasks(self, cluster_name, service_name):
74-
return self.boto.list_tasks(
75-
cluster=cluster_name,
76-
serviceName=service_name
77-
)
75+
tasks_paginator = self.boto.get_paginator(u'list_tasks')
76+
return list(itertools.chain.from_iterable(
77+
res['taskArns'] for res in tasks_paginator.paginate(
78+
cluster=cluster_name,
79+
serviceName=service_name
80+
)
81+
))
7882

7983
def describe_tasks(self, cluster_name, task_arns):
8084
return self.boto.describe_tasks(cluster=cluster_name, tasks=task_arns)
@@ -1173,11 +1177,11 @@ def is_deployed(self, service):
11731177
cluster_name=service.cluster,
11741178
service_name=service.name
11751179
)
1176-
if not running_tasks[u'taskArns']:
1180+
if not running_tasks:
11771181
return service.desired_count == 0
11781182
running_count = self.get_running_tasks_count(
11791183
service=service,
1180-
task_arns=running_tasks[u'taskArns']
1184+
task_arns=running_tasks
11811185
)
11821186
return service.desired_count == running_count
11831187

tests/test_ecs.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,11 @@
386386
u'test-task': RESPONSE_TASK_DEFINITION_2,
387387
}
388388

389-
RESPONSE_LIST_TASKS_2 = {
390-
u"taskArns": [TASK_ARN_1, TASK_ARN_2]
391-
}
389+
RESPONSE_LIST_TASKS_2 = [TASK_ARN_1, TASK_ARN_2]
392390

393-
RESPONSE_LIST_TASKS_1 = {
394-
u"taskArns": [TASK_ARN_1]
395-
}
391+
RESPONSE_LIST_TASKS_1 = [TASK_ARN_1]
396392

397-
RESPONSE_LIST_TASKS_0 = {
398-
u"taskArns": []
399-
}
393+
RESPONSE_LIST_TASKS_0 = []
400394

401395
RESPONSE_DESCRIBE_TASKS = {
402396
u"tasks": [PAYLOAD_TASK_1, PAYLOAD_TASK_2]
@@ -1001,7 +995,7 @@ def test_client_describe_unknown_task_definition(client):
1001995

1002996
def test_client_list_tasks(client):
1003997
client.list_tasks(u'test-cluster', u'test-service')
1004-
client.boto.list_tasks.assert_called_once_with(cluster=u'test-cluster', serviceName=u'test-service')
998+
client.boto.get_paginator.assert_called_once_with(u'list_tasks')
1005999

10061000

10071001
def test_client_describe_tasks(client):

0 commit comments

Comments
 (0)