Package ganeti :: Module 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]
 
__init__(self, queue, job_id, ops)
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
list
GetInfo(self, fields)
Returns information about a job.
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

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

Class Methods [hide private]
_JobQueue
Restore(cls, queue, state)
Restore a _QueuedJob from serialized state:
source code
Static Methods [hide private]
 
_InitInMemory(obj)
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
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, queue, job_id, ops)
(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
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

Restore(cls, queue, state)
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
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

GetInfo(self, fields)

source code 

Returns information about a job.

Parameters:
  • fields (list) - names of fields to return
Returns: list
list with one element for each field
Raises:

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