| 1 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
|
| 6 |
from taskgraph.actions.registry import register_callback_action |
| 7 |
from taskgraph.actions.util import ( |
| 8 |
combine_task_graph_files, |
| 9 |
create_tasks, |
| 10 |
fetch_graph_and_labels, |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
@register_callback_action( |
| 15 |
name="add-new-jobs", |
| 16 |
title="Add new jobs", |
| 17 |
symbol="add-new", |
| 18 |
description="Add new jobs using task labels.", |
| 19 |
order=100, |
| 20 |
context=[], |
| 21 |
schema={ |
| 22 |
"type": "object", |
| 23 |
"properties": { |
| 24 |
"tasks": { |
| 25 |
"type": "array", |
| 26 |
"description": "An array of task labels", |
| 27 |
"items": {"type": "string"}, |
| 28 |
}, |
| 29 |
"times": { |
| 30 |
"type": "integer", |
| 31 |
"default": 1, |
| 32 |
"minimum": 1, |
| 33 |
"maximum": 100, |
| 34 |
"title": "Times", |
| 35 |
"description": "How many times to run each task.", |
| 36 |
}, |
| 37 |
}, |
| 38 |
}, |
| 39 |
) |
| 40 |
def add_new_jobs_action(parameters, graph_config, input, task_group_id, task_id): |
| 41 |
decision_task_id, full_task_graph, label_to_taskid = fetch_graph_and_labels( |
| 42 |
parameters, graph_config, task_group_id=task_group_id |
| 43 |
) |
| 44 |
|
| 45 |
to_run = [] |
| 46 |
for elem in input["tasks"]: |
| 47 |
if elem in full_task_graph.tasks: |
| 48 |
to_run.append(elem) |
| 49 |
else: |
| 50 |
raise Exception(f"{elem} was not found in the task-graph") |
| 51 |
|
| 52 |
times = input.get("times", 1) |
| 53 |
for i in range(times): |
| 54 |
create_tasks( |
| 55 |
graph_config, |
| 56 |
to_run, |
| 57 |
full_task_graph, |
| 58 |
label_to_taskid, |
| 59 |
parameters, |
| 60 |
decision_task_id, |
| 61 |
f"{i}", |
| 62 |
) |
| 63 |
combine_task_graph_files(list(range(times))) |