#!/usr/bin/python

# ======================================================
# Sample script:
#   job submission with email callback
#
# PipelineFX, 2007
#
# ======================================================

import os, sys

# Make sure that qb module is in the python path
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');
else:
    sys.path.append('/usr/local/pfx/qube/api/python');

import qb

def main():
    # Set basic job properties
    job = {}
    job['name']         = 'cmdline with email callback'
    job['prototype']    = 'cmdline'

    # Set the package properties
    job['package']      = {}
    job['package']['cmdline'] = 'set'

    # Create the email callback and set the address to send it to
    # NOTE: Make sure that the Qube Supervisor has the email settings configured
    job['mailaddress'] = 'yourname@your.address.com'
    job['callbacks'] = [{'triggers':'done-job-self', 'language':'mail'}]
    
    # Submit
    listOfSubmittedJobs = qb.submit([job])

    # Report on submit results
    for job in listOfSubmittedJobs:
        print job['id']

if __name__ == "__main__":
    main()
    sys.exit(0)
