Skip to content

Commit 4744c12

Browse files
fix: add pagination for list incomplete tasks (#804)
1 parent 1e130f2 commit 4744c12

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/taskgraph/util/taskcluster.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,19 @@ def send_email(address, subject, content, link):
411411
def list_task_group_incomplete_tasks(task_group_id):
412412
"""Generate the incomplete tasks in a task group"""
413413
queue = get_taskcluster_client("queue")
414-
response = queue.listTaskGroup(task_group_id)
415-
416-
if not response or "tasks" not in response:
417-
return
418-
419-
tasks = response.get("tasks", [])
420-
for task in tasks:
421-
if (status := task.get("status")) is not None: # type: ignore
422-
if (task_id := status.get("taskId")) and status.get("state") in [
423-
"running",
424-
"pending",
425-
"unscheduled",
426-
]:
427-
yield task_id
414+
415+
incomplete_tasks = []
416+
417+
def pagination_handler(response):
418+
incomplete_tasks.extend(
419+
task["status"]["taskId"]
420+
for task in response["tasks"]
421+
if task["status"]["state"] in ("running", "pending", "unscheduled")
422+
)
423+
424+
queue.listTaskGroup(task_group_id, paginationHandler=pagination_handler)
425+
426+
return incomplete_tasks
428427

429428

430429
@functools.lru_cache(maxsize=None)

test/test_util_taskcluster.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,37 @@ def test_list_task_group_incomplete_tasks(responses, root_url):
401401
json={
402402
"tasks": [
403403
{"status": {"taskId": "1", "state": "pending"}},
404-
{"status": {"taskId": "2", "state": "unscheduled"}},
404+
{"status": {"taskId": "2", "state": "completed"}},
405405
{"status": {"taskId": "3", "state": "running"}},
406-
{"status": {"taskId": "4", "state": "completed"}},
406+
],
407+
"continuationToken": "page2",
408+
},
409+
)
410+
411+
responses.get(
412+
f"{root_url}/api/queue/v1/task-group/{tgid}/list",
413+
json={
414+
"tasks": [
415+
{"status": {"taskId": "4", "state": "unscheduled"}},
416+
{"status": {"taskId": "5", "state": "failed"}},
417+
{"status": {"taskId": "6", "state": "pending"}},
418+
],
419+
"continuationToken": "page3",
420+
},
421+
)
422+
423+
responses.get(
424+
f"{root_url}/api/queue/v1/task-group/{tgid}/list",
425+
json={
426+
"tasks": [
427+
{"status": {"taskId": "7", "state": "running"}},
428+
{"status": {"taskId": "8", "state": "completed"}},
407429
]
408430
},
409431
)
410432

411433
result = list(tc.list_task_group_incomplete_tasks(tgid))
412-
assert result == ["1", "2", "3"]
434+
assert result == ["1", "3", "4", "6", "7"]
413435

414436

415437
def test_get_ancestors(responses, root_url):

0 commit comments

Comments
 (0)