Here, we demonstrate how to submit a job through the Python API that runs a python script as a callback. This example shows a very simple callback that writes the job id and python information to a file.
Python callback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | job = { 'prototype' : 'cmdline' , 'name' : 'python callback test' , 'package' : { 'cmdline' : 'hostname' , }, 'callbacks' : [ { 'language' : 'python' , 'triggers' : 'done-job-self' , 'code' : ''' try: import sys fh = open('c:/temp/err.txt', 'w') fh.close() fh = open('c:/temp/foo.txt', 'w') fh.write('Hello from job id %s\\n' % qb.jobid()) fh.write('sys.version : %s\\n' % sys.version) fh.write('sys.version info : %s\\n' % '.'.join([str(x) for x in sys.version_info])) fh.write('sys.executable : %s\\n' % sys.executable) fh.close() except Exception, e: fh = open('c:/temp/err.txt', 'w') fh.write('Error from job id %s\\n' % qb.jobid()) fh.write('%s\\n' % e) fh.close() ''' } ] } print '%(id)s: %(name)s' % qb.submit(job)[ 0 ] |