Bug 1626795: [hg-push] Don't trigger tasks on old pushes; r=aki
authorTom Prince <mozilla@hocat.ca>
Thu, 02 Apr 2020 20:12:05 +0000
changeset 213 ec62d2df61eeb3b4297deafbf8e314bc17e98d1d
parent 212 dd04f10e617d6f7447b620a91aeabfe30addaf6e
child 214 ab1d110d850a29d70e0a1a8688b95daea743ae74
push id153
push usermozilla@hocat.ca
push dateMon, 06 Apr 2020 17:31:35 +0000
treeherderci-admin@ec62d2df61ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaki
bugs1626795
Bug 1626795: [hg-push] Don't trigger tasks on old pushes; r=aki Differential Revision: https://phabricator.services.mozilla.com/D69294
taskcluster/docker/hg-push/make_decision.py
--- a/taskcluster/docker/hg-push/make_decision.py
+++ b/taskcluster/docker/hg-push/make_decision.py
@@ -3,26 +3,30 @@
 # -*- coding: utf-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 os
+import time
 
 import jsone
 import requests
 import slugid
 import yaml
 from requests.adapters import HTTPAdapter
 from requests.packages.urllib3.util.retry import Retry
 
 import taskcluster
 
+# Allow triggering on-push task for pushes up to 3 days old.
+MAX_TIME_DRIFT = 3 * 24 * 60 * 60
+
 SESSION = requests.Session()
 adapter = HTTPAdapter(
     max_retries=Retry(
         total=3,
         read=3,
         connect=3,
         backoff_factor=0.3,
         status_forcelist=(500, 502, 503, 504),
@@ -121,16 +125,20 @@ def main():
         return
 
     # The hg-push hook can be triggered manually, so we throw out everything
     # from the input, other than the revision, and get the pushinfo from
     # hg.mozilla.org.
     head_rev = pulse_payload["data"]["heads"][0]
     push_info = get_push_info(head_rev)
 
+    if time.time() - push_info["date"] > MAX_TIME_DRIFT:
+        print("Push is to old, not triggering tasks".format(head_count))
+        return
+
     rendered = render_tc_yml(get_tc_yml(head_rev), push_info, head_rev)
 
     task_count = len(rendered["tasks"])
     if task_count != 1:
         print("Rendered result has {} tasks; only one supported".format(task_count))
         return
     task = rendered["tasks"][0]
     taskId = task.pop("taskId")