Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/taskgraph/util/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,20 @@ def list_tasks(index_path):
in the index. Results are sorted by expiration date from oldest to newest.
"""
index = get_taskcluster_client("index")
response = index.listTasks(index_path, {})
tasks = []

if not response or "tasks" not in response:
return []
def pagination_handler(response):
tasks.extend(response["tasks"])

tasks = response.get("tasks", [])
index.listTasks(index_path, paginationHandler=pagination_handler)

# We can sort on expires because in the general case
# all of these tasks should be created with the same expires time so they end up in
# order from earliest to latest action. If more correctness is needed, consider
# fetching each task and sorting on the created date.
tasks.sort(key=lambda t: parse_time(t["expires"]))

task_ids = [t["taskId"] for t in tasks if "taskId" in t]
task_ids = [t["taskId"] for t in tasks]

return task_ids

Expand Down
50 changes: 32 additions & 18 deletions test/test_util_taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,28 +233,42 @@ def mock_client(service):
mock_index.findArtifactFromTask.assert_called_with(index, path)


def test_list_tasks(monkeypatch):
def test_list_tasks(monkeypatch, responses, root_url):
index = "foo"

mock_index = mock.MagicMock()

def mock_client(service):
if service == "index":
return mock_index
return mock.MagicMock()

monkeypatch.setattr(tc, "get_taskcluster_client", mock_client)

mock_index.listTasks.return_value = {
"tasks": [
{"taskId": "123", "expires": "2023-02-10T19:07:33.700Z"},
{"taskId": "abc", "expires": "2023-02-09T19:07:33.700Z"},
]
}
monkeypatch.setattr(os, "environ", {"TASKCLUSTER_ROOT_URL": root_url})
responses.get(
f"{root_url}/api/index/v1/tasks/{index}",
json={
"tasks": [
{
"namespace": "foo.A08Cbf8KSFqMsa3J0m-yTg",
"taskId": "A08Cbf8KSFqMsa3J0m-yTg",
"rank": 0,
"data": {},
"expires": "2025-10-29T11:58:45.474Z",
}
],
"continuationToken": "qzxkXG8ZWa",
},
)
responses.get(
f"{root_url}/api/index/v1/tasks/{index}",
json={
"tasks": [
{
"namespace": "foo.a0ha8axBTVCCgq1zm6uUhQ",
"taskId": "a0ha8axBTVCCgq1zm6uUhQ",
"rank": 0,
"data": {},
"expires": "2025-10-29T11:57:33.217Z",
}
],
},
)

result = tc.list_tasks(index)
assert result == ["abc", "123"]
mock_index.listTasks.assert_called_with(index, {})
assert result == ["a0ha8axBTVCCgq1zm6uUhQ", "A08Cbf8KSFqMsa3J0m-yTg"]


def test_parse_time():
Expand Down
Loading