AWS Thinkbox Discussion Forums

deadline script getting info from job

My goal is to write a generic python script called create_draft_job(deadlineJobID=12345)

It’s a python function which takes a single arg which is the deadline job ID. From there I’d like to get the job info from the ID, for example the data displayed in deadline, like job name, output path…etc. From there I would use that data to run a custom draft job. Making it a dependency of the the arg job ID. So it wont render the draft job until the task is finished. I’m not sure if there is already an easier way to automate the creation of a draft job from a deadline job. Keeping in mind we are not using the Deadline Submission GUI provided in the applications since we have to implement studio specific things, like output overrides and shotgun integrations.

I’m assuming something like this would be possible to do.

The template is already made. My main question is, is it possible for me to run a python function and get deadline info for a job based on the job ID?

How can i interact with deadline without using the webservice. I just want to communication directly with deadline using python.

To answer your question, there isn’t a helper function for that info. If you’re outside of the UIs and DeadlineCommand scripting most of the internal API is missing for you (C# doesn’t load well in pure CPython :smiley:).

For building a Draft job, I’d crib the code from these files in your repo:
“[repo]\submission\Draft\Main\DraftSubmissionBase.py” - SubmitDraftJob() for the possible plugin info bits
“[repo]\events\DraftEventPlugin\DraftEventPlugin.py” - CreateDraftJob() for how we usually create a dependent Draft job from existing

Now, because you don’t have access to the job object from CPython land, your next best approach is to have DeadlineCommand dump the data for you. You have to popen() and run this:

c:\Program Files\Thinkbox\Deadline9\bin>deadlinecommand getjob 596fce52652b55247472c3de true

That’ll dump the job info in a ConfigParser-friendly format. You can take the output from popen as a string, stuff it in a StringIO and feed that right into a ConfigParser object. The key of the job section will be the job id.

That’s my high-level view of things anyway. We can dive into any of those sections or veer off another way if you need.

Is there a way to connect to deadline without having to run the pulse server and just communicate directly with the deadline repo of jobs?

FYI. The web service is now separate from Pulse. For a quick overview of all of Deadline’s API entry points:
deadline.thinkboxsoftware.com/fe … -code-here

Re-reading your original description, I think all you really need to do here, is just review the py code in our current Draft event plugin that ships in Deadline. I’m assuming your system would want to always fire whenever something happened to a job state? (Such as a certain type of job completed).

Here’s a quick example of using the INI output from DLC:


if __name__ == "__main__":
    job_id = '598a2811652b5513800ea23c'
    job_text = CallDeadlineCommand(['GetJob', job_id, 'True'])

    print(job_text)
    
    job_parser = configparser.ConfigParser(interpolation = None) # We have a % in output
    job_parser.read_string(job_text)
    
    for section in job_parser.sections(): # There's only one here
        for k, v in job_parser.items(section):
            print("{0: <25} {1}".format(k + ':', v))

And the full script including CallDeadlineCommand():

example.py.txt (1.93 KB)

Yeah i’d like to trigger a submission once a job is complete.

Event plugins would be your new best friend then!
docs.thinkboxsoftware.com/produ … ugins.html

OnJobFinishedCallback

Many examples in our shipping code and also on GitHub: github.com/ThinkboxSoftware/Dea … tom/events

This is awesome Owen. I gave a quick glance over the docs. How do I trigger this event. Do i have to pass it as an argument, secondly how to I have it only trigger on specific jobs. For my case, jobs sent to the farm from 3ds Max or Maya?

Are there ways to test some sort of conditional saying

 'if job.comment == 'Max' do....

I think I’ve got it working. I noticed i can get the Job.Plugin data. How can I get the path to the frames being rendered from the job. Is there an api help file showing all the available properties of the job i can get?

docs.thinkboxsoftware.com/produ … 1_job.html

I’m almost done bothering you :slight_smile:

So i have an event called SimpleExample and the even is enabled in Deadline.

What im trying to do is write to a json file after the deadline job has finished the name of the job.plugin. Just for a super simple example. However it appears it never gets triggered. Here is my code. My install is Deadline 8 vanilla install. Is there an error log i can see why or if gets triggered. Maybe its failing on the json import, im not sure. You have me pretty stoked about this stuff Mike!!

How can i get this to execute when a job is finished?

[code]
import re
import json

from System.IO import *
from System.Text import *
from Deadline.Events import *
from Deadline.Scripting import *

This is the function that Deadline calls to get an instance of the main DeadlineEventListener class.

def GetDeadlineEventListener():
return MyEvent()

This is the main DeadlineEventListener class for MyEvent.

class MyEvent (DeadlineEventListener):

def __init__( self ):
	self.OnJobFinishedCallback += self.OnJobFinished

def OnJobFinished( self, job ):
	data = {'name': job.JobPlugin}
	fp = 'C:/Users/jmartini/Desktop/Trash/deadline.json'
	with open(fp, 'w') as outfile:
		json.dump(data, outfile)
		[/code]

got it working! the github samples are out dated and no longer work.
i fixed my version

Deadline job object needs to be serialised as its a .NET object.

[code]from System.Diagnostics import *
from System.IO import *
from Newtonsoft.Json import *

from Deadline.Events import *
from Deadline.Scripting import *

import json
import traceback

##############################################################################################

This is the function called by Deadline to get an instance of the Nuke event listener.

##############################################################################################
def GetDeadlineEventListener():
return NukeEventListener()

def CleanupDeadlineEventListener( eventListener ):
eventListener.Cleanup()

###############################################################

The Nuke event listener class.

###############################################################
class NukeEventListener( DeadlineEventListener ):
def init( self ):
self.OnJobFinishedCallback += self.OnJobFinished

def Cleanup( self ):
    del self.OnJobFinishedCallback

## This is called when the job finishes rendering.
def OnJobFinished( self, job ):
    
    if job.PluginName == "Nuke":
        try:
            ClientUtils.LogText( "Completed Nuke Job" )

            data = JsonConvert.SerializeObject( job )
            ClientUtils.LogText( "json object: %s" % data )

            fp = "/Users/mikeowen/Desktop/deadline.json"
            
            with open(fp, 'w') as outfile:
                json.dump(data, outfile)
        except:
            ClientUtils.LogText( traceback.format_exc() )[/code]

Last time I checked, all our Github examples are working well. Which ones doesn’t work and on what line?

I’ll find the one i used that didn’t work.

Is there a console i can print to and test outputs, or should i just write to txt file?

Why the need to serialize to .net?

There’s console tab/window in the monitor (once you enable it trough right clicking in one of the window frames)
docs.thinkboxsoftware.com/produ … ht=console

Also if you “print” in event script you get what ever you printed in the log(job reports) for that event script.

Just an aside here, from a dev-perspective I tend to build my proof of concept in a DeadlineCommand script and tie it into the event system last. Tends to allow for faster turnaround time since I don’t have to trigger the event every test phase.

As far as the Github examples, please do let us know. I’m sure one or two could use a refresh by now, and I’m willing to take the blame for that. :smiley:

How do you build a deadline command script. Currently I’m writing an event for deadline, however each time i run the code i have to submit a job and read the reports.

Privacy | Site terms | Cookie preferences