Author Topic: TIP: submitting a job via python with an email callback  (Read 13106 times)

Scot Brew

  • Hero Member
  • *****
  • Posts: 272
    • PipelineFX
TIP: submitting a job via python with an email callback
« on: May 11, 2009, 06:21:21 PM »
Here is a sample python script that will submit a cmdline job with an email callback so it will email a specified user upon job completion.

Job Submission with email callback

Code: [Select]
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)


Additional Information:
Some example python submission scripts can be found at qube/examples/python.  Another place to check is the source code for the QubeGUI scripts at qube/api/python/qb/gui/.

opet

  • Newbie
  • *
  • Posts: 1
Re: TIP: submitting a job via python with an email callback
« Reply #1 on: June 30, 2011, 11:45:53 AM »
Does this still work in 6.1.1? I've been trying everything, but I can not get the email callback to work. Any tips? Attached my script as well.

Code: [Select]
import c4d, os, sys
from c4d import gui
"""
Sends a c4d-file to Qube
Copyright Oyvind Pettersen
"""



# 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():


    #ask for project name
    pNameDefault = "Prosjektnavn"
    pName = gui.InputDialog(pNameDefault) #pass it
    print pName

    pUserDefault = "Brukernavn (nXXXXX)"
    pUser = gui.InputDialog(pUserDefault) #pass it
    print pUser


    rd=doc.GetActiveRenderData() #get the current renderdata
    filePath=rd[c4d.RDATA_PATH] #get save path
    print filePath

    multiPath=rd[c4d.RDATA_MULTIPASS_FILENAME] #get multi path
    print multiPath

    multiPass=rd[c4d.RDATA_MULTIPASS_ENABLE]
    print multiPass
   
    ad=doc.GetDocumentPath() + "/" + doc.GetDocumentName() #get document path
    print ad

    frame = doc.GetTime().GetFrame(doc.GetFps())
    print frame

    #format=rd[c4d.RDATA_FORMAT]
    #print format

    frameFrom=rd[c4d.RDATA_FRAMEFROM].GetFrame(doc.GetFps())
    print frameFrom

    frameTo=rd[c4d.RDATA_FRAMETO].GetFrame(doc.GetFps())
    print frameTo

    #frameStep=rd[c4d.RDATA_FRAMESTEP]
    #print frameStep

    ## BEGING QUBE ##

    # Set basic job properties
    job = {}
    job['name']         = pName
    job['cpus']         = 4
    job['prototype']    = 'cmdrange'
    job['requirements'] = ''
    job['priority']     = '10'
    if pUser:
        print "Emailing"
        job['triggers'] = 'done-job-self'
        job['language'] = 'mail'
        job['mailaddress']  = pUser + '@nrk.no'
        job['callbacks'] = [{'triggers':'done-job-self', 'language':'mail'}]
       
   
    # Set the package properties
    job['package']      = {}
    #job['package']['-render'] = '/Volumes/GrafiSAN/Qube/Cinema4D/Prosjekter/Royal_Wedding/wedding_part_2.c4d'
    if multiPass:
        job['package']['cmdline'] = '"/Applications/MAXON/CINEMA 4D R12/CINEMA 4D.app/Contents/MacOS/CINEMA 4D" -nogui -frame QB_FRAME_START QB_FRAME_END QB_FRAME_STEP -oimage "'+filePath+'" -omultipass "'+multiPath+'" -render "' + ad + '"'
    else:
        job['package']['cmdline'] = '"/Applications/MAXON/CINEMA 4D R12/CINEMA 4D.app/Contents/MacOS/CINEMA 4D" -nogui -frame QB_FRAME_START QB_FRAME_END QB_FRAME_STEP -oimage "'+filePath+'" -render "' + ad + '"'

    # Calculate agenda from range
    #agendaRange = '0-60x10'
    agendaRange = str(frameFrom) + '-' + str(frameTo)
    agenda = qb.genframes(agendaRange)
   
    # Set the outputPaths in the resultpackage for each agenda item
    #for i in agenda:
    #    i.resultpackage({'outputPaths': 'C:/YOUR/OUTPUT/PATH/GOES/HERE.tga'})

    # Set the job agenda
    job['agenda'] = agenda

    # Submit
    listOfSubmittedJobs = qb.submit([job])

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


if __name__=='__main__':
    main()