The next step is to understand basic dependancies
Feel free to download an run the below script as it will only setup a job that will run a "sleep" command on the worker
below is the code with commented explanations of its contents
Code Block |
---|
#!/usr/bin/python
# Below are required imports for the script to run
import os, sys
# The below few lines of code are to determine the OS of the machine that your running
# this script from and then define the location of the Qube! API
if 'QBDIR' in os.environ:
sys.path.append('%s/api/python' % os.environ['QBDIR']);
elif os.uname()[0] == 'Darwin':
sys.path.append('/Applications/pfx/qube/api/python');
elif os.uname()[0] == 'Linux':
sys.path.append('/usr/local/pfx/qube/api/python');
else:
sys.path.append('c:/program files/pfx/qube/api/python');
# The below line of code is to import the above defined Qube! API
import qb
# Below is the main function to run in this script
def main():
# ----------------Start creation of Parent Job----------------------------------------
# Below creates an empty dictionary to be filled by the following lines of code
job = {}
# Below defines the name of the Qube! job
job['name'] = 'python parent job'
# Below defines how many Instances/subjobs the job is to spawn
job['cpus'] = 1
# Below defines the internal Qube! jobtype to be used to execute the job
job['prototype'] = 'cmdrange'
# The below parameters are explained further in the "Job submission with job package explained" page
package = {}
job['package'] = package
job['package']['cmdline'] = 'sleep QB_FRAME_NUMBER'
# Below defines the Agenda/Range of the job this will fill the Frames/Work section of the Qube! GUI
# "0-60x10" is range 0-60 in chunks of 10 frames
agendaRange = '0-60x10'
# Below defines the internal command required to generate the agenda
agenda = qb.genframes(agendaRange)
# Below defines the job details for the agenda
job['agenda'] = agenda
# Below creates an empty list filled by the following lines of code
listOfJobsToSubmit = []
# Below evaluates the Parent job to be submitted and adds the to the above list
listOfJobsToSubmit.append(job)
# Below evaluates the Parent job to be submitted and adds the to the above list
listOfSubmittedJobs = qb.submit(listOfJobsToSubmit)
# Below calls the Parent job to be submitted and then prints the job ID
parentJobID = listOfSubmittedJobs[0]['id']
print 'parent: %d' % parentJobID
# ----------------Start creation of Child Job----------------------------------------
# Below creates an empty dictionary to be filled by the following lines of code
job = {}
# Below defines the name of the Qube! job
job['name'] = 'python child job'
# Below defines how many Instances/subjobs the job is to spawn
job['cpus'] = 1
# Below defines how many Instances/subjobs the job is to spawn
job['prototype'] = 'cmdrange'
# Below defines the jobs dependancy which links back to the first job in this script
job['waitfor'] = parentJobID
# The below parameters are explained further in the "Job submission with job package explained" page
package = {}
job['package'] = package
job['package']['cmdline'] = 'sleep 20'
# Below creates an empty list filled by the following lines of code
listOfJobsToSubmit = []
# Below evaluates the Child jobs to be submitted and adds the to the above list
listOfJobsToSubmit.append(job)
# Below calls the Child jobs to be submitted and then prints the job IDs
listOfSubmittedJobs = qb.submit(listOfJobsToSubmit)
for job in listOfSubmittedJobs:
print 'child: %d' % job['id']
# Below runs the "main" function
if __name__ == "__main__":
main()
sys.exit(0)
|
A non edited version of this script can be found along with others :
- Windows - C:\Program Files\pfx\qube\examples\jobSubmit03.py
- OSX - /Application/pfx/qube/examples/jobSubmit03.py
- Linux - /usr/local/pfx/qube/examples/jobSubmit03.py
Online - Python