Module xg :: Class Job
[hide private]
[frames] | no frames]

Class Job

source code

object --+
         |
        Job

A class for working with an Xgrid job.

Instance Methods [hide private]
 
__init__(self, jobID=u'999999999', connection=None)
An Xgrid job class.
source code
 
_updateInfo(self) source code
 
_updateSpecification(self) source code
 
_update(self) source code
 
_checkJobID(self, result) source code
 
_checkGridID(self, result, gridID) source code
 
specification(self, update=1)
Return the Xgrid job specification.
source code
 
info(self, update=1)
Return the current status information about a job.
source code
 
results(self, stdout='', outdir='', stderr='', block=10, silent=False)
Retrieve the results of an Xgrid job.
source code
Job
submit(self, cmd, args='', stdin='', indir='', email='', gridID=u'0', silent=False)
Submits a single task job to the specified grid.
source code
Job
batch(self, specification, gridID=u'0', silent=False)
Submits a batch job to the specified grid.
source code
 
perform(self, action)
Performs an action on a job.
source code
 
stop(self)
Stops the job.
source code
 
suspend(self)
Suspends the job.
source code
 
resume(self)
Resumes the job.
source code
 
delete(self)
Deletes the job.
source code
 
restart(self)
Restarts the job.
source code
 
__repr__(self)
repr(x)
source code
 
printInfo(self, verbose=True)
Prints the info() dictionary of a job.
source code
 
printSpecification(self)
Print the job specification used to submit the job.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, jobID=u'999999999', connection=None)
(Constructor)

source code 

An Xgrid job class.

This class allows a user to work with an Xgrid job. It provides capabilities for starting jobs, managing them and retrieving their results.

Job instances are created in two ways:

  1. By calling the job() or jobs() methods of the Grid or Controller classes.
  2. By simply creating a new Job object:
>>> j = Job(u'200')    # Create a new job with id of 200
Parameters:
  • jobID (unicode, str or int) - The job identifier of the job. To create a new job, leave blank.
  • connection (Connection) - Instance of Connection class. If empty a default Connection object is used.
Overrides: object.__init__

specification(self, update=1)

source code 

Return the Xgrid job specification.

The Xgrid job specification is the dictionary that Xgrid uses to submit the job. It contains keys that describe the command arguments, directories, etc.

info(self, update=1)

source code 

Return the current status information about a job.

The job info is a dictionary of keys describing the current state of the job. This includes start/stop dates, name, etc.

The method printInfo() prints the info() dictionary in a nice form.

Parameters:
  • update (boolean) - A boolean flag that determines whether or not the internal state is updated upon creation. This involves a call to the Xgrid controller.

results(self, stdout='', outdir='', stderr='', block=10, silent=False)

source code 

Retrieve the results of an Xgrid job.

This method provides both a blocking and nonblocking method of getting the results of an Xgrid job. The job does not need to be completed to retrieve the results. Because of this, the results method can be used to get partial results while the job continues to run. It can also automatically name output files.

Parameters:
  • stdout (str) - The local file in which to put the stdout stream of the remote job. If this is empty, the method will automatically generate a name in the local directory of the form: xgridjob-jobID.out. This file always is placed in the cwd rather than the outdir
  • stderr (str) - The local file in which to put the stderr stream of the remote job. If this is empty, the method will automatically generate a name in the local directory of the form: xgridjob-jobID.err.
  • outdir (str) - The local directory in which to put the files retrieved from the remote job. This is only for files other than the stdout and stderr files. When empty, the other files are not brought back. This is to prevent any accidental overwrites of results.
  • block (int) - Whether or not to block until the job is finished. If block=0, partially completed results are retrieved and the job will continue to run. If block > 0, the job status is queried every block seconds and the results are returned when the job is completed.
  • silent (boolean) - Silence all messages.

submit(self, cmd, args='', stdin='', indir='', email='', gridID=u'0', silent=False)

source code 

Submits a single task job to the specified grid.

This is a nonblocking job submission method for a single job with no sub-tasks. For more complicated jobs with sub-tasks, use the batch() method.

Job results can be obtained by calling the results() method.

Parameters:
  • cmd (str) - The command to execute as a string. The executable is not copied if the full path is given, otherwise it is.
  • args (list or str) - The command line arguments to be passed to the command.
  • stdin (str) - A local file to use as the stdin stream for the job.
  • indir (str) - A local directory to copy to the remote agent.
  • email (str) - An email to which notification will be send of various job state changes.
  • gridID (unicode, str or int) - The identifier of the Grid to which the job will be submitted. If empty, the default grid u'0' is used.
  • silent (boolean) - If set to True will slience all messages.
Returns: Job
Initialized Job object for sumbitted job.

batch(self, specification, gridID=u'0', silent=False)

source code 

Submits a batch job to the specified grid.

This is a nonblocking job submission method used for submitting complex multi-task jobs. For single task jobs, use submit().

To retrieve job results, use the results() method.

Parameters:
  • specification (JobSpecification) - The job specification of the job, which must be an instance of the JobSpecification class. See the docstring for JobSpecification for more details.
  • gridID (unicode, str or int) - The identifier of the Grid to which the job will be submitted. If empty, the default grid u'0' is used.
  • silent (boolean) - If set to True will slience all messages.
Returns: Job
Initialized Job object for sumbitted job.

perform(self, action)

source code 

Performs an action on a job.

Parameters:
  • action (str) - The action to be performed as a string. Implemented actions are stop, resume, delete, restart, and suspend.

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)