#!/usr/bin/python import os, sys 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'); import qb # This script demonstrates how to submit a job with agenda (frame) timeouts, # using a simple "cmdrange" job. # The trick is to set up a timeout value for agenda items via the # agenda_timeout parameter, but also to set up and attach a callback that does # something (in our case, it fails the agenda item) when the timeout has been # reached. def main(): # First, we set up the job dict as we would normally do for an # agenda-based job. Here, we're submitting a "cmdrange" job, requesting # 10 subjobs ('cpus') to process it. job = {} job['name'] = 'agenda timeout job submitted from python' job['cpus'] = 1 job['prototype'] = 'cmdrange' # our test job will run a "sleep 60" command to emulate a real job package = {} job['package'] = package job['package']['cmdline'] = 'sleep 60' # The agenda for the job. We have 1-10 frames. agendaRange = '1-10' agenda = qb.genframes(agendaRange) job['agenda'] = agenda # We set the agendatimeout to 10 seconds. When that amount of time is # elapsed, the system will generate a "timeout-work" event job['agenda_timeout'] = 10 # We also set up a callback for the timeout event job['callbacks'] = [{'triggers':'timeout-work-self-*', 'language':'qube', 'code':'fail-work-self'}] listOfJobsToSubmit = [] listOfJobsToSubmit.append(job) # submit the job! listOfSubmittedJobs = qb.submit(listOfJobsToSubmit) for job in listOfSubmittedJobs: print job['id'] if __name__ == "__main__": main() sys.exit(0)