diff --git a/taskcluster/taskgraph/optimize/backstop.py b/taskcluster/taskgraph/optimize/backstop.py index 395f4e965e42..e265b495e6e0 100644 --- a/taskcluster/taskgraph/optimize/backstop.py +++ b/taskcluster/taskgraph/optimize/backstop.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, print_function, unicode_literals from taskgraph.optimize import OptimizationStrategy, register_strategy +from taskgraph.util.attributes import match_run_on_projects @register_strategy("backstop") @@ -25,10 +26,21 @@ class PushInterval(OptimizationStrategy): Args: push_interval (int): Number of pushes + remove_on_projects (set): For non-autoland projects, the task will + be removed if we're running on one of these projects, otherwise + it will be kept. """ - def __init__(self, push_interval): + def __init__(self, push_interval, remove_on_projects=None): self.push_interval = push_interval + self.remove_on_projects = remove_on_projects or {'try'} def should_remove_task(self, task, params, _): + project = params["project"] + + # Scheduling on a backstop only makes sense on autoland. For other projects, + # remove the task if the project matches self.remove_on_projects. + if project != 'autoland': + return match_run_on_projects(project, self.remove_on_projects) + # On every Nth push, want to run all tasks. return int(params["pushlog_id"]) % self.push_interval != 0 diff --git a/taskcluster/taskgraph/test/test_optimize_strategies.py b/taskcluster/taskgraph/test/test_optimize_strategies.py index 43e6f7697798..bf179aea643d 100644 --- a/taskcluster/taskgraph/test/test_optimize_strategies.py +++ b/taskcluster/taskgraph/test/test_optimize_strategies.py @@ -336,6 +336,15 @@ def test_push_interval(params): scheduled = {t.label for t in default_tasks if not opt.should_remove_task(t, params, None)} assert scheduled == all_labels + # On non-autoland projects the 'remove_on_projects' value is used. + params['project'] = 'mozilla-central' + scheduled = {t.label for t in default_tasks if not opt.should_remove_task(t, params, None)} + assert scheduled == all_labels + + params['project'] = 'try' + scheduled = {t.label for t in default_tasks if not opt.should_remove_task(t, params, None)} + assert scheduled == set() + if __name__ == '__main__': main()