Package ganeti :: Package jqueue :: Class _QueuedJob
[hide private]
[frames] | no frames]

Class _QueuedJob

source code


In-memory job representation.

This is what we use to track the user-submitted jobs. Locking must be taken care of by users of this class.

Instance Methods [hide private]
 
AddReasons(self, pickup=False)
Extend the reason trail
source code
 
__init__(self, queue, job_id, ops, writable)
Constructor for the _QueuedJob.
source code
 
__repr__(self)
repr(x)
source code
dict
Serialize(self)
Serialize the _JobQueue instance.
source code
 
CalcStatus(self)
Compute the status of this job.
source code
int
CalcPriority(self)
Gets the current priority for this job.
source code
list
GetLogEntries(self, newer_than)
Selectively returns the log entries.
source code
 
MarkUnfinishedOps(self, status, result)
Mark unfinished opcodes with a given status and result.
source code
 
Finalize(self)
Marks the job as finalized.
source code
tuple; (bool, string)
Cancel(self)
Marks job as canceled/-ing if possible.
source code
tuple; (bool, string)
ChangePriority(self, priority)
Changes the job priority.
source code
 
SetPid(self, pid)
Sets the job's process ID
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
_JobQueue
Restore(cls, queue, state, writable, archived)
Restore a _QueuedJob from serialized state:
source code
Static Methods [hide private]
 
_InitInMemory(obj, writable)
Initializes in-memory variables.
source code
Instance Variables [hide private]
  end_timestamp
the timestamp for end of execution
  id
the job ID
int log_serial
holds the index for the next log entry
list ops
the list of _QueuedOpCode that constitute the job
JobQueue queue
the parent queue
  received_timestamp
the timestamp for when the job was received
  start_timestmap
the timestamp for start of execution
  writable
Whether the job is allowed to be modified
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

AddReasons(self, pickup=False)

source code 

Extend the reason trail

Add the reason for all the opcodes of this job to be executed.

__init__(self, queue, job_id, ops, writable)
(Constructor)

source code 

Constructor for the _QueuedJob.

Parameters:
  • queue (JobQueue) - our parent queue
  • job_id (job_id) - our job id
  • ops (list) - the list of opcodes we hold, which will be encapsulated in _QueuedOpCodes
  • writable (bool) - Whether job can be modified
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

Restore(cls, queue, state, writable, archived)
Class Method

source code 

Restore a _QueuedJob from serialized state:

Parameters:
  • queue (JobQueue) - to which queue the restored job belongs
  • state (dict) - the serialized state
  • writable (bool) - Whether job can be modified
  • archived (bool) - Whether job was already archived
Returns: _JobQueue
the restored _JobQueue instance

Serialize(self)

source code 

Serialize the _JobQueue instance.

Returns: dict
the serialized state

CalcStatus(self)

source code 

Compute the status of this job.

This function iterates over all the _QueuedOpCodes in the job and based on their status, computes the job status.

The algorithm is:

  • if we find a cancelled, or finished with error, the job status will be the same
  • otherwise, the last opcode with the status one of:
    • waitlock
    • canceling
    • running

    will determine the job status

  • otherwise, it means either all opcodes are queued, or success, and the job status will be the same
Returns:
the job status

CalcPriority(self)

source code 

Gets the current priority for this job.

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

Returns: int

GetLogEntries(self, newer_than)

source code 

Selectively returns the log entries.

Parameters:
  • newer_than (None or int) - if this is None, return all log entries, otherwise return only the log entries with serial higher than this value
Returns: list
the list of the log entries selected

MarkUnfinishedOps(self, status, result)

source code 

Mark unfinished opcodes with a given status and result.

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

Parameters:
  • status - a given opcode status
  • result - the opcode result

Cancel(self)

source code 

Marks job as canceled/-ing if possible.

Returns: tuple; (bool, string)
Boolean describing whether job was successfully canceled or marked as canceling and a text message

ChangePriority(self, priority)

source code 

Changes the job priority.

Parameters:
  • priority (int) - New priority
Returns: tuple; (bool, string)
Boolean describing whether job's priority was successfully changed and a text message

SetPid(self, pid)

source code 

Sets the job's process ID

Parameters:
  • pid (int) - the process ID