tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

add_new_jobs.py (1765B)


      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 .registry import register_callback_action
      7 from .util import combine_task_graph_files, create_tasks, fetch_graph_and_labels
      8 
      9 
     10 @register_callback_action(
     11    name="add-new-jobs",
     12    title="Add new jobs",
     13    symbol="add-new",
     14    description="Add new jobs using task labels.",
     15    order=100,
     16    context=[],
     17    schema={
     18        "type": "object",
     19        "properties": {
     20            "tasks": {
     21                "type": "array",
     22                "description": "An array of task labels",
     23                "items": {"type": "string"},
     24            },
     25            "times": {
     26                "type": "integer",
     27                "default": 1,
     28                "minimum": 1,
     29                "maximum": 100,
     30                "title": "Times",
     31                "description": "How many times to run each task.",
     32            },
     33        },
     34    },
     35 )
     36 def add_new_jobs_action(parameters, graph_config, input, task_group_id, task_id):
     37    decision_task_id, full_task_graph, label_to_taskid, _ = fetch_graph_and_labels(
     38        parameters, graph_config
     39    )
     40 
     41    to_run = []
     42    for elem in input["tasks"]:
     43        if elem in full_task_graph.tasks:
     44            to_run.append(elem)
     45        else:
     46            raise Exception(f"{elem} was not found in the task-graph")
     47 
     48    times = input.get("times", 1)
     49    for i in range(times):
     50        create_tasks(
     51            graph_config,
     52            to_run,
     53            full_task_graph,
     54            label_to_taskid,
     55            parameters,
     56            decision_task_id,
     57            i,
     58        )
     59    combine_task_graph_files(list(range(times)))