Revision 8f5c488d lib/jqueue.py

b/lib/jqueue.py
95 95
  @ivar stop_timestamp: timestamp for the end of the execution
96 96

  
97 97
  """
98
  __slots__ = ["input", "status", "result", "log",
98
  __slots__ = ["input", "status", "result", "log", "priority",
99 99
               "start_timestamp", "exec_timestamp", "end_timestamp",
100 100
               "__weakref__"]
101 101

  
......
114 114
    self.exec_timestamp = None
115 115
    self.end_timestamp = None
116 116

  
117
    # Get initial priority (it might change during the lifetime of this opcode)
118
    self.priority = getattr(op, "priority", constants.OP_PRIO_DEFAULT)
119

  
117 120
  @classmethod
118 121
  def Restore(cls, state):
119 122
    """Restore the _QueuedOpCode from the serialized form.
......
132 135
    obj.start_timestamp = state.get("start_timestamp", None)
133 136
    obj.exec_timestamp = state.get("exec_timestamp", None)
134 137
    obj.end_timestamp = state.get("end_timestamp", None)
138
    obj.priority = state.get("priority", constants.OP_PRIO_DEFAULT)
135 139
    return obj
136 140

  
137 141
  def Serialize(self):
......
149 153
      "start_timestamp": self.start_timestamp,
150 154
      "exec_timestamp": self.exec_timestamp,
151 155
      "end_timestamp": self.end_timestamp,
156
      "priority": self.priority,
152 157
      }
153 158

  
154 159

  
......
302 307

  
303 308
    return status
304 309

  
310
  def CalcPriority(self):
311
    """Gets the current priority for this job.
312

  
313
    Only unfinished opcodes are considered. When all are done, the default
314
    priority is used.
315

  
316
    @rtype: int
317

  
318
    """
319
    priorities = [op.priority for op in self.ops
320
                  if op.status not in constants.OPS_FINALIZED]
321

  
322
    if not priorities:
323
      # All opcodes are done, assume default priority
324
      return constants.OP_PRIO_DEFAULT
325

  
326
    return min(priorities)
327

  
305 328
  def GetLogEntries(self, newer_than):
306 329
    """Selectively returns the log entries.
307 330

  

Also available in: Unified diff