Do not reuse cancelled jobs. Do not consider nil outputs from
authorTom Clegg <tom@curoverse.com>
Sun, 13 Apr 2014 00:50:23 +0000 (20:50 -0400)
committerTom Clegg <tom@curoverse.com>
Sun, 13 Apr 2014 00:50:23 +0000 (20:50 -0400)
incomplete jobs when deciding whether a script is deterministic.

services/api/app/controllers/arvados/v1/jobs_controller.rb

index 178b48f173d58e47b5c590149d8b7f966b872dec..0a4e308c7700479234dfb2c13a7584f8e6fb9a73 100644 (file)
@@ -20,25 +20,33 @@ class Arvados::V1::JobsController < ApplicationController
                                  resource_attrs[:script_version],
                                  resource_attrs[:exclude_script_versions])
     if !resource_attrs[:nondeterministic] and !resource_attrs[:no_reuse]
-      # Search for jobs where the script_version is in the list of commits
+      # Search for jobs whose script_version is in the list of commits
       # returned by find_commit_range
       @object = nil
+      @incomplete_job = nil
       Job.readable_by(current_user).where(script: resource_attrs[:script],
                                           script_version: r).
         each do |j|
         if j.nondeterministic != true and
             j.success != false and
+            !j.cancelled_at and
             j.script_parameters == resource_attrs[:script_parameters]
-          # Record the first job in the list
-          if !@object
-            @object = j
-          end
-          # Ensure that all candidate jobs actually did produce the same output
-          if @object.output != j.output
-            @object = nil
-            break
+          if j.success.nil?
+            # We'll use this if we don't find a job that has completed
+            @incomplete_job ||= j
+          else
+            # Record the first job in the list
+            if !@object
+              @object = j
+            end
+            # Ensure that all candidate jobs actually did produce the same output
+            if @object.output != j.output
+              @object = nil
+              break
+            end
           end
         end
+        @object ||= @incomplete_job
         if @object
           return show
         end