Bug 1351010 - Fix return statements in optimize.py; r?dustin draft
authorAyodeji Oyewole <ayodeji.oyewole@gmail.com>
Sat, 01 Apr 2017 15:59:36 -0400
changeset 555877 7678cb347fe74189db46ff36c2b7ac743df63f42
parent 552146 5182b2c4b963ed87d038c7d9a4021463917076cd
child 622726 d3862cdeeed7655e5c26a7997e445bce3b4a63e2
push id52371
push userbmo:ayodeji.oyewole@gmail.com
push dateWed, 05 Apr 2017 02:51:03 +0000
reviewersdustin
bugs1351010
milestone55.0a1
Bug 1351010 - Fix return statements in optimize.py; r?dustin MozReview-Commit-ID: ctgm1fw0Fo *** Bug 1351010 - Completely fixed; r?dustin MozReview-Commit-ID: HKoWcINVSnV
taskcluster/taskgraph/optimize.py
--- a/taskcluster/taskgraph/optimize.py
+++ b/taskcluster/taskgraph/optimize.py
@@ -71,21 +71,21 @@ def resolve_task_references(label, task_
 def optimize_task(task, params):
     """
     Optimize a single task by running its optimizations in order until one
     succeeds.
     """
     for opt in task.optimizations:
         opt_type, args = opt[0], opt[1:]
         opt_fn = _optimizations[opt_type]
-        optimized, task_id = opt_fn(task, params, *args)
-        if optimized or task_id:
-            return optimized, task_id
+        opt_result = opt_fn(task, params, *args)
+        if opt_result:
+            return opt_result
 
-    return False, None
+    return False
 
 
 def annotate_task_graph(target_task_graph, params, do_not_optimize,
                         named_links_dict, label_to_taskid, existing_tasks):
     """
     Annotate each task in the graph with .optimized (boolean) and .task_id
     (possibly None), following the rules for optimization and calling the task
     kinds' `optimize_task` method.
@@ -113,17 +113,25 @@ def annotate_task_graph(target_task_grap
         if label in do_not_optimize:
             optimized = False
         # Let's check whether this task has been created before
         elif existing_tasks is not None and label in existing_tasks:
             optimized = True
             replacement_task_id = existing_tasks[label]
         # otherwise, examine the task itself (which may be an expensive operation)
         else:
-            optimized, replacement_task_id = optimize_task(task, params)
+            opt_result = optimize_task(task, params)
+
+            # use opt_result to determine values for optimized, replacement_task_id
+            optimized = True
+            replacement_task_id = None
+            if opt_result is False:
+                optimized = False
+            elif opt_result is not True:
+                replacement_task_id = opt_result
 
         task.optimized = optimized
         task.task_id = replacement_task_id
         if replacement_task_id:
             label_to_taskid[label] = replacement_task_id
 
         if optimized:
             if replacement_task_id:
@@ -190,21 +198,21 @@ def optimization(name):
 
 @optimization('index-search')
 def opt_index_search(task, params, index_path):
     try:
         task_id = find_task_id(
             index_path,
             use_proxy=bool(os.environ.get('TASK_ID')))
 
-        return True, task_id
+        return task_id or True
     except requests.exceptions.HTTPError:
         pass
 
-    return False, None
+    return False
 
 
 @optimization('seta')
 def opt_seta(task, params):
     bbb_task = False
 
     # for bbb tasks we need to send in the buildbot buildername
     if task.task.get('provisionerId', '') == 'buildbot-bridge':
@@ -216,25 +224,25 @@ def opt_seta(task, params):
     # we would like to return 'False, None' while it's high_value_task
     # and we wouldn't optimize it. Otherwise, it will return 'True, None'
     if is_low_value_task(label,
                          params.get('project'),
                          params.get('pushlog_id'),
                          params.get('pushdate'),
                          bbb_task):
         # Always optimize away low-value tasks
-        return True, None
+        return True
     else:
-        return False, None
+        return False
 
 
 @optimization('files-changed')
 def opt_files_changed(task, params, file_patterns):
     # pushlog_id == -1 - this is the case when run from a cron.yml job
     if params.get('pushlog_id') == -1:
-        return True, None
+        return True
 
     changed = files_changed.check(params, file_patterns)
     if not changed:
         logger.debug('no files found matching a pattern in `when.files-changed` for ' +
                      task.label)
-        return True, None
-    return False, None
+        return True
+    return False