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?
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 ).
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:
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.
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():
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
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?
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]
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.
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.