fune/taskcluster/gecko_taskgraph/optimize/backstop.py
Andrew Halberstadt 95449daa6d Bug 1732723 - Rename "taskgraph" Python module to "gecko_taskgraph". r=jmaher
For a long time two copies of the 'taskgraph' module have existed in parallel.
We've attempted to keep them in sync, but over time they have diverged and the
maintenance burden has increased.

In order to reduce this burden, we'd like to re-join the two code bases. The
canonical repo will be the one that lives outside of mozilla-central, and this
module will depend on it. Since they both have the same module name (taskgraph)
we need to rename the version in mozilla-central to avoid collisions.

Other consumers of 'taskgraph' (like mobile repos) have standardized on
'<project>_taskgraph' as their module names. So replicating that here as well.

Differential Revision: https://phabricator.services.mozilla.com/D127118
2021-09-30 09:50:08 -04:00

46 lines
1.5 KiB
Python

# 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/.
from gecko_taskgraph.optimize import All, OptimizationStrategy, register_strategy
from gecko_taskgraph.util.backstop import BACKSTOP_PUSH_INTERVAL
@register_strategy("skip-unless-backstop")
class SkipUnlessBackstop(OptimizationStrategy):
"""Always removes tasks except on backstop pushes."""
def should_remove_task(self, task, params, _):
return not params["backstop"]
class SkipUnlessPushInterval(OptimizationStrategy):
"""Always removes tasks except every N pushes.
Args:
push_interval (int): Number of pushes
"""
def __init__(self, push_interval, remove_on_projects=None):
self.push_interval = push_interval
@property
def description(self):
return f"skip-unless-push-interval-{self.push_interval}"
def should_remove_task(self, task, params, _):
# On every Nth push, want to run all tasks.
return int(params["pushlog_id"]) % self.push_interval != 0
# Strategy to run tasks on "expanded" pushes, currently defined as pushes that
# are half the backstop interval. The 'All' composite strategy means that the
# "backstop" strategy will prevent "expanded" from applying on backstop pushes.
register_strategy(
"skip-unless-expanded",
args=(
"skip-unless-backstop",
SkipUnlessPushInterval(BACKSTOP_PUSH_INTERVAL / 2),
),
)(All)