Revision 34327f51

b/lib/constants.py
453 453
JOB_STATUS_SUCCESS = "success"
454 454
JOB_STATUS_ERROR = "error"
455 455

  
456
# OpCode status
457
# not yet finalized
456 458
OP_STATUS_QUEUED = "queued"
457 459
OP_STATUS_WAITLOCK = "waiting"
458 460
OP_STATUS_CANCELING = "canceling"
459 461
OP_STATUS_RUNNING = "running"
462
# finalized
460 463
OP_STATUS_CANCELED = "canceled"
461 464
OP_STATUS_SUCCESS = "success"
462 465
OP_STATUS_ERROR = "error"
466
OPS_FINALIZED = frozenset([OP_STATUS_CANCELED,
467
                           OP_STATUS_SUCCESS,
468
                           OP_STATUS_ERROR])
463 469

  
464 470
# Execution log types
465 471
ELOG_MESSAGE = "message"
b/lib/jqueue.py
313 313

  
314 314
    return entries
315 315

  
316
  def MarkUnfinishedOps(self, status, result):
317
    """Mark unfinished opcodes with a given status and result.
318

  
319
    This is an utility function for marking all running or waiting to
320
    be run opcodes with a given status. Opcodes which are already
321
    finalised are not changed.
322

  
323
    @param status: a given opcode status
324
    @param result: the opcode result
325

  
326
    """
327
    not_marked = True
328
    for op in self.ops:
329
      if op.status in constants.OPS_FINALIZED:
330
        assert not_marked, "Finalized opcodes found after non-finalized ones"
331
        continue
332
      op.status = status
333
      op.result = result
334
      not_marked = False
335

  
316 336

  
317 337
class _JobQueueWorker(workerpool.BaseWorker):
318 338
  """The actual job workers.
......
593 613
                          constants.JOB_STATUS_CANCELING):
594 614
            logging.warning("Unfinished job %s found: %s", job.id, job)
595 615
            try:
596
              for op in job.ops:
597
                op.status = constants.OP_STATUS_ERROR
598
                op.result = "Unclean master daemon shutdown"
616
              job.MarkUnfinishedOps(constants.OP_STATUS_ERROR,
617
                                    "Unclean master daemon shutdown")
599 618
            finally:
600 619
              self.UpdateJobUnlocked(job)
601 620

  
......
1157 1176
    elif job_status == constants.JOB_STATUS_WAITLOCK:
1158 1177
      # The worker will notice the new status and cancel the job
1159 1178
      try:
1160
        for op in job.ops:
1161
          op.status = constants.OP_STATUS_CANCELING
1179
        job.MarkUnfinishedOps(constants.OP_STATUS_CANCELING, None)
1162 1180
      finally:
1163 1181
        self.UpdateJobUnlocked(job)
1164 1182
      return (True, "Job %s will be canceled" % job.id)
......
1169 1187

  
1170 1188
    """
1171 1189
    try:
1172
      for op in job.ops:
1173
        op.status = constants.OP_STATUS_CANCELED
1174
        op.result = "Job canceled by request"
1190
      job.MarkUnfinishedOps(constants.OP_STATUS_CANCELED,
1191
                            "Job canceled by request")
1175 1192
    finally:
1176 1193
      self.UpdateJobUnlocked(job)
1177 1194

  

Also available in: Unified diff