Package schrodinger :: Package job :: Module queue :: Class BaseJob
[hide private]
[frames] | no frames]

Class BaseJob

A base job class for jobs run under JobDJ.

The main methods to be implemented in subclasses are:

  1. doCommand - The method that does the real work of the job, either running a simple local calculation or submitting a job to job control.
  2. update - A method called periodically while a job is running to update its current state.
  3. _getState - The get method used in the state property, used by JobDJ to determine the job's current state.

A few additional methods only need to be implemented in special situations:

  1. finalize - If you want custom behavior in your finalize method, override this method.
  2. cancelSubmitted - If the job can run under a queue, implementing this method allows jobs that are waiting in the submitted state to be restarted immediately on a newly available non-queue host.
  3. getStatusStrings - If you want to use the JobDJ print summary, this method should be updated to provide more useful information.

The execution point for all jobs is in the BaseJob.run method. That method calls preCommand, doCommand and postCommand in order.

For jobs that are run locally, all main computation should be done in the doCommand method method. Note that the doCommand method blocks until completion and so no additional work will be done (e.g. job updates or submissions) until it returns. For this reason, only short jobs should be run locally without job control.

Instance Methods [hide private]
 
__init__(self, command_dir=None)
 
runsLocally(self)
Return True if the job runs on the JobDJ control host, False if not.
 
update(self)
Update the current job status, stored in the state property.
 
maxFailuresReached(self, msg)
This is a method that will be called after the job has failed and the maximum number of failures per JobDJ run has been reached.
 
finalize(self)
Clean up after a job successfully runs.
 
doCommand(self, *args, **kwargs)
Execute the command associated with this job.
 
run(self, *args, **kwargs)
Run the job.
 
getCommandDir(self)
Return the launch/command directory name.
 
preCommand(self)
A method to make pre-command changes, like cd'ing to the correct directory to run the command in.
 
setup(self)
A method to do initial setup; executed after preCommand, just before doCommand.
 
postCommand(self)
A method to restore things to the pre-command state.
 
_getState(self)
Return the current state of the job.
 
_setState(self, state)
Set the current state of the job.
 
isComplete(self)
Returns True if this job finished successfully
 
hasStarted(self)
Returns True if this job has started (not waiting)
 
getStatusStrings(self)
Return a tuple of status strings for printing by JobDJ.
 
getJobDJ(self)
Return the JobDJ instance that this job has been added to.
 
__lt__(self, other)
This comparison method determines the order of execution for jobs in the JobDJ _jobqueue heap.
 
addPrereq(self, job)
Add a job that is an immediate prerequisite for this one.
 
addGroupPrereq(self, job)
Make all jobs connected to job prerequisites of all jobs connected to this Job.
 
getPrereqs(self)
Return a set of all immediate prerequisites for this job.
 
_pruneGraph(self)
Remove this job from the prerequisites list of any dependents and return a list of any dependent jobs that no longer have unfinished prerequisites.
 
genAllPrereqs(self, seen=None)
A generator that yields all jobs that are prerequisites on this one.
 
genAllJobs(self, seen=None)
A generator that yields all jobs connected to this one.
 
addFinalizer(self, function, run_dir=None)
Add a function to be invoked when the job completes successfully.
Class Variables [hide private]
  init_count = 0
  state = property(_getState, _setState)
Method Details [hide private]

__init__(self, command_dir=None)
(Constructor)

 
Parameters:
  • command_dir (pathname) - The directory from which to run the command.

runsLocally(self)

 

Return True if the job runs on the JobDJ control host, False if not. Jobs that run locally don't need hosts.

There is no limit on the number of locally run jobs.

update(self)

 

Update the current job status, stored in the state property.

When a job is running, this method will be called periodically by JobDJ until the job state property is DONE.

maxFailuresReached(self, msg)

 

This is a method that will be called after the job has failed and the maximum number of failures per JobDJ run has been reached. After invoking this method, JobDJ will raise a RuntimeError and the process will exit.

run(self, *args, **kwargs)

 

Run the job.

The steps taken are as follows:

  1. Execute the preCommand method for things like changing the working directory.
  2. Call the doCommand to do the actual work of computation or job launching.
  3. Call the postCommand method to undo the changes from the preCommand that need to be undone.

getCommandDir(self)

 

Return the launch/command directory name. If None is returned, the job will be launched in the current directory.

_getState(self)

 

Return the current state of the job.

Note that this method can be overridden by subclasses that wish to provide for restartability at a higher level than unpickling BaseJob instances. For example, by examining some external condition (e.g. presence of output files) the state DONE could be returned immediately and the job would not run.

_setState(self, state)

 

Set the current state of the job.

Note that this method can be overridden by subclasses that wish to take action every time the state of a job changes.

Parameters:
  • state - Must be one of the module level variables WAITING, ACTIVE, FAILED, FAILED_RETRYABLE, or DONE.

getStatusStrings(self)

 

Return a tuple of status strings for printing by JobDJ.

The strings returned are (status, jobid, name, host).

addFinalizer(self, function, run_dir=None)

 

Add a function to be invoked when the job completes successfully.

See also the add_multi_job_finalizer function.