jqueue: Don't update file in MarkUnfinishedOps
authorMichael Hanselmann <hansmi@google.com>
Thu, 9 Sep 2010 13:53:56 +0000 (15:53 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 10 Sep 2010 11:23:15 +0000 (13:23 +0200)
This reduced the number of updates to the job files. It's used in two places
while processing a job and the file is updated just afterwards.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/jqueue.py

index e2a9baa..fb269f5 100644 (file)
@@ -377,17 +377,14 @@ class _QueuedJob(object):
     @param result: the opcode result
 
     """
-    try:
-      not_marked = True
-      for op in self.ops:
-        if op.status in constants.OPS_FINALIZED:
-          assert not_marked, "Finalized opcodes found after non-finalized ones"
-          continue
-        op.status = status
-        op.result = result
-        not_marked = False
-    finally:
-      self.queue.UpdateJobUnlocked(self)
+    not_marked = True
+    for op in self.ops:
+      if op.status in constants.OPS_FINALIZED:
+        assert not_marked, "Finalized opcodes found after non-finalized ones"
+        continue
+      op.status = status
+      op.result = result
+      not_marked = False
 
 
 class _OpExecCallbacks(mcpu.OpExecCbBase):
@@ -947,6 +944,7 @@ class JobQueue(object):
             logging.warning("Unfinished job %s found: %s", job.id, job)
             job.MarkUnfinishedOps(constants.OP_STATUS_ERROR,
                                   "Unclean master daemon shutdown")
+            self.UpdateJobUnlocked(job)
 
         logging.info("Job queue inspection finished")
       finally:
@@ -1474,12 +1472,16 @@ class JobQueue(object):
     if job_status == constants.JOB_STATUS_QUEUED:
       job.MarkUnfinishedOps(constants.OP_STATUS_CANCELED,
                             "Job canceled by request")
-      return (True, "Job %s canceled" % job.id)
+      msg = "Job %s canceled" % job.id
 
     elif job_status == constants.JOB_STATUS_WAITLOCK:
       # The worker will notice the new status and cancel the job
       job.MarkUnfinishedOps(constants.OP_STATUS_CANCELING, None)
-      return (True, "Job %s will be canceled" % job.id)
+      msg = "Job %s will be canceled" % job.id
+
+    self.UpdateJobUnlocked(job)
+
+    return (True, msg)
 
   @_RequireOpenQueue
   def _ArchiveJobsUnlocked(self, jobs):