Skip to content

Commit

Permalink
Do not apply skip-unless-changed for cron triggers.
Browse files Browse the repository at this point in the history
  • Loading branch information
afranchuk authored and ahal committed Nov 18, 2024
1 parent a37236a commit 2ebcbd2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
10 changes: 3 additions & 7 deletions docs/reference/optimization-strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ Strategies for Removing Tasks
skip-unless-changed
~~~~~~~~~~~~~~~~~~~

.. note::

This strategy is only implemented for Mercurial repositories hosted on
``hg.mozilla.org``.

The :class:`skip-unless-changed
<taskgraph.optimize.strategies.SkipUnlessChanged>` strategy will optimize the
target task away *unless* a specified file is modified. Glob patterns are
supported.
target task away *unless* a specified file is modified. When there is no
difference between head and base revs (for example, cron or action tasks), this
optimization will not apply. Glob patterns are supported.

Example:

Expand Down
5 changes: 3 additions & 2 deletions src/taskgraph/optimize/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def check(self, files_changed, patterns):
return False

def should_remove_task(self, task, params, file_patterns):
# pushlog_id == -1 - this is the case when run from a cron.yml job or on a git repository
if params.get("repository_type") == "hg" and params.get("pushlog_id") == -1:
# skip-unless-changed should not apply when there is no commit delta,
# such as for cron and action tasks (there will never be file changes)
if params.get("head_rev") == params.get("base_rev"):
return False

changed = self.check(params["files_changed"], file_patterns)
Expand Down
2 changes: 1 addition & 1 deletion test/test_optimize_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_index_search(caplog, responses, params, state, expires, expected, logs)
{"files_changed": ["bar.txt"]}, ["foo.txt"], True, id="files don't match"
),
pytest.param(
{"repository_type": "hg", "pushlog_id": -1, "files_changed": ["bar.txt"]},
{"head_rev": "8843d7f92416211de9ebb963ff4ce28125932878", "base_rev": "8843d7f92416211de9ebb963ff4ce28125932878", "files_changed": ["bar.txt"]},
["foo.txt"],
False,
id="cron task",
Expand Down

0 comments on commit 2ebcbd2

Please sign in to comment.