Skip to content

Commit

Permalink
Override the existing_tasks explicitly provided in the action's input (
Browse files Browse the repository at this point in the history
…mozilla#683)

* Override the existing_tasks explicitly provided in the action's input

* Log the labels and task ids of any existing tasks that are overridden

---------

Co-authored-by: Evgeny Pavlov <[email protected]>
  • Loading branch information
2 people authored and gregtatum committed Jun 25, 2024
1 parent 1282307 commit 7a06b76
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions taskcluster/translations_taskgraph/actions/train.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import logging

from taskgraph.actions.registry import register_callback_action
from taskgraph.decision import taskgraph_decision
Expand All @@ -10,6 +12,8 @@

from translations_taskgraph.parameters import get_defaults

logger = logging.getLogger(__name__)

TRAIN_ON_PROJECTS = (
"https://github.com/mozilla/firefox-translations-training",
"https://github.com/mozilla-releng/staging-firefox-translations-training",
Expand Down Expand Up @@ -398,6 +402,35 @@ def train_action(parameters, graph_config, input, task_group_id, task_id):
# an identical name.
parameters["existing_tasks"] = get_ancestors(start_task_ids)

# Override the `existing_tasks` explicitly provided in the action's input
existing_tasks = input.pop("existing_tasks", {})

# Find and log `overridden_existing_tasks`
overridden_existing_tasks = {
existing_task: parameters["existing_tasks"][existing_task]
for existing_task in existing_tasks.keys()
if existing_task in parameters["existing_tasks"]
}

if overridden_existing_tasks:
logger.info(
f"Old values for `overridden_existing_tasks`: {json.dumps(overridden_existing_tasks, indent=2)}"
)

# Do the override!
parameters["existing_tasks"].update(existing_tasks)

# Log the new values for the `overridden_existing_tasks`
new_values_for_overridden = {
existing_task: parameters["existing_tasks"][existing_task]
for existing_task in overridden_existing_tasks.keys()
}

if new_values_for_overridden:
logger.info(
f"New values for `overridden_existing_tasks`: {json.dumps(new_values_for_overridden, indent=2)}"
)

parameters["target_tasks_method"] = "train-target-tasks"
parameters["optimize_target_tasks"] = True
parameters["tasks_for"] = "action"
Expand Down

0 comments on commit 7a06b76

Please sign in to comment.