Skip to content

Commit 8fe339a

Browse files
feat: allow setting per-task priority (#534)
* feat: allow setting per-task priority The run and task transforms only allowed using the default per-project priority. * style: pre-commit.ci auto fixes [...] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 40dff3b commit 8fe339a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/taskgraph/transforms/run/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# possibly modified by the run implementation. See
5050
# taskcluster/taskgraph/transforms/task.py for the schema details.
5151
Required("description"): task_description_schema["description"],
52+
Optional("priority"): task_description_schema["priority"],
5253
Optional("attributes"): task_description_schema["attributes"],
5354
Optional("task-from"): task_description_schema["task-from"],
5455
Optional("dependencies"): task_description_schema["dependencies"],

src/taskgraph/transforms/task.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ def _run_task_suffix():
7272
),
7373
): object,
7474
},
75+
Optional("priority"): Any(
76+
"highest",
77+
"very-high",
78+
"high",
79+
"medium",
80+
"low",
81+
"very-low",
82+
"lowest",
83+
),
7584
# Soft dependencies of this task, as a list of tasks labels
7685
Optional("soft-dependencies"): [str],
7786
# Dependencies that must be scheduled in order for this task to run.

test/test_transforms_task.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,3 +942,70 @@ def test_default_expires_after(run_transform, graph_config, expires_after, test_
942942
assert task_dict["task"]["expires"] == {"relative-datestamp": expires_after}
943943
else:
944944
assert task_dict["task"]["expires"] == {"relative-datestamp": "28 days"}
945+
946+
947+
@pytest.mark.parametrize(
948+
"test_task",
949+
(
950+
{
951+
"description": "fake description",
952+
"name": "fake-task-name",
953+
"worker-type": "t-linux",
954+
"worker": {
955+
"docker-image": "fake-image-name",
956+
"max-run-time": 1800,
957+
},
958+
},
959+
{
960+
"description": "fake description",
961+
"name": "fake-task-name",
962+
"worker-type": "t-linux",
963+
"worker": {
964+
"docker-image": "fake-image-name",
965+
"max-run-time": 1800,
966+
},
967+
"priority": "high",
968+
},
969+
),
970+
)
971+
def test_task_priority(run_transform, graph_config, test_task):
972+
params = FakeParameters(
973+
{
974+
"base_repository": "[email protected]://github.com/mozilla/example.git",
975+
"build_date": 0,
976+
"build_number": 1,
977+
"head_repository": "[email protected]://github.com/mozilla/example.git",
978+
"head_rev": "abcdef",
979+
"head_ref": "default",
980+
"level": "1",
981+
"moz_build_date": 0,
982+
"next_version": "1.0.1",
983+
"owner": "some-owner",
984+
"project": "some-project",
985+
"pushlog_id": 1,
986+
"repository_type": "git",
987+
"target_tasks_method": "test_method",
988+
"tasks_for": "github-pull-request",
989+
"try_mode": None,
990+
"version": "1.0.0",
991+
},
992+
)
993+
994+
transform_config = TransformConfig(
995+
"check_priority",
996+
str(here),
997+
{},
998+
params,
999+
{},
1000+
graph_config,
1001+
write_artifacts=False,
1002+
)
1003+
1004+
task_dict = deepcopy(test_task)
1005+
1006+
task_dict = run_transform(task.transforms, task_dict, config=transform_config)[0]
1007+
priority = test_task.get("priority")
1008+
if priority:
1009+
assert task_dict["task"]["priority"] == priority
1010+
else:
1011+
assert task_dict["task"]["priority"] == graph_config["task-priority"]

0 commit comments

Comments
 (0)