MarkUnfinishedOps: update job file on disk
authorGuido Trotter <ultrotter@google.com>
Thu, 24 Jun 2010 14:41:58 +0000 (16:41 +0200)
committerGuido Trotter <ultrotter@google.com>
Mon, 28 Jun 2010 11:04:50 +0000 (12:04 +0100)
Every time we call MarkUnfinishedOps we do it in a try/finally block
that updates the job file. With this patch we move the try/finally
inside. CancelJobUnlocked is removed, because it just becomes a wrapper
over MarkUnfinishedOps with two constant values.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/jqueue.py

index ed6fc0c..a0402a0 100644 (file)
@@ -381,14 +381,17 @@ class _QueuedJob(object):
     @param result: the opcode result
 
     """
-    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
+    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)
 
 
 class _OpExecCallbacks(mcpu.OpExecCbBase):
@@ -670,7 +673,8 @@ class _JobQueueWorker(workerpool.BaseWorker):
       except CancelJob:
         queue.acquire()
         try:
-          queue.CancelJobUnlocked(job)
+          job.MarkUnfinishedOps(constants.OP_STATUS_CANCELED,
+                                "Job canceled by request")
         finally:
           queue.release()
       except errors.GenericError, err:
@@ -817,11 +821,8 @@ class JobQueue(object):
                           constants.JOB_STATUS_WAITLOCK,
                           constants.JOB_STATUS_CANCELING):
             logging.warning("Unfinished job %s found: %s", job.id, job)
-            try:
-              job.MarkUnfinishedOps(constants.OP_STATUS_ERROR,
-                                    "Unclean master daemon shutdown")
-            finally:
-              self.UpdateJobUnlocked(job)
+            job.MarkUnfinishedOps(constants.OP_STATUS_ERROR,
+                                  "Unclean master daemon shutdown")
 
         logging.info("Job queue inspection finished")
       finally:
@@ -1344,29 +1345,16 @@ class JobQueue(object):
       return (False, "Job %s is no longer waiting in the queue" % job.id)
 
     if job_status == constants.JOB_STATUS_QUEUED:
-      self.CancelJobUnlocked(job)
+      job.MarkUnfinishedOps(constants.OP_STATUS_CANCELED,
+                            "Job canceled by request")
       return (True, "Job %s canceled" % job.id)
 
     elif job_status == constants.JOB_STATUS_WAITLOCK:
       # The worker will notice the new status and cancel the job
-      try:
-        job.MarkUnfinishedOps(constants.OP_STATUS_CANCELING, None)
-      finally:
-        self.UpdateJobUnlocked(job)
+      job.MarkUnfinishedOps(constants.OP_STATUS_CANCELING, None)
       return (True, "Job %s will be canceled" % job.id)
 
   @_RequireOpenQueue
-  def CancelJobUnlocked(self, job):
-    """Marks a job as canceled.
-
-    """
-    try:
-      job.MarkUnfinishedOps(constants.OP_STATUS_CANCELED,
-                            "Job canceled by request")
-    finally:
-      self.UpdateJobUnlocked(job)
-
-  @_RequireOpenQueue
   def _ArchiveJobsUnlocked(self, jobs):
     """Archives jobs.