* Allow the system user to update job columns, even if the job is "locked"
[arvados.git] / services / api / script / crunch-dispatch.rb
index 693dfbdb7fc049289067d94e866b48049bc8c2cb..a54e8acf726c55e91d98f54874674988f02d80a4 100755 (executable)
@@ -298,7 +298,6 @@ class Dispatcher
     job_done = j_done[:job]
     $stderr.puts "dispatch: child #{pid_done} exit"
     $stderr.puts "dispatch: job #{job_done.uuid} end"
-    $redis.publish job_done.uuid, "end"
 
     # Ensure every last drop of stdout and stderr is consumed
     read_pipes
@@ -309,9 +308,18 @@ class Dispatcher
     # Wait the thread
     j_done[:wait_thr].value
 
+    jobrecord = Job.find_by_uuid(job_done.uuid)
+    jobrecord.running = false
+    if jobrecord.finished_at == nil
+      jobrecord.finished_at = Time.now
+    end
+    jobrecord.save!
+    
     # Invalidate the per-job auth token
     j_done[:job_auth].update_attributes expires_at: Time.now
 
+    $redis.publish job_done.uuid, "end"
+
     @running.delete job_done.uuid
   end