AWS Thinkbox Discussion Forums

Help with understanding the scripting reference?

Hi guys. I have been really struggling to understand anything in the scripting reference. I’ve gotten stuff to work a little bit by looking into the example scripts that came with Deadline, but I’m afraid I cannot make any sense at all out of the scripting reference supplied. I am having to launch deadlinecommand.exe as a subprocess and use large sweeping commands that will give me ALL of the information for a job, and then I parse out the stuff I’m looking for. This is obviously not ideal.

For example, I’m trying to write a script that will just give users an ETA based on how many tasks they have total, completed, queued, etc. I want to incorporate the “Task Time” as supplied in the tasks panel in the monitor. I am able to find most of that information, but I can’t seem to figure out how to get the specifics from the tasks panel. Here is my script so far.

from Deadline.Scripting import *
from DeadlineUI.Controls.Scripting.DeadlineScriptDialog import DeadlineScriptDialog
import sys
import os
#import string
#import datetime
#import timespan

scriptDialog = None

def main():

global scriptDialog
scriptDialog = DeadlineScriptDialog()

timeHack = 12

submitUser = ClientUtils.GetDeadlineUser()
jobs = MonitorUtils.GetSelectedJobs()
myJob = jobs[0]

queuedFrames = myJob.JobQueuedTasks
renderingFrames = myJob.JobRenderingTasks
failedFrames = myJob.JobFailedTasks
completedFrames = myJob.JobCompletedTasks

‘’‘Here is where I want to get the render time for each task for the given job. I have tried every combination of everything I find in the scripting reference and I can’t figure this out. I then want to add up all the time and do some calculations, then make timeHack equal to my result and tell the users’’’

scriptDialog.ShowDialog( False )
scriptDialog.CloseDialog()

scriptDialog.ShowMessageBox( "ETA is %s hours.      "%timeHack, "ETA" )

I guess my question is, what is the proper procedure for getting all of the task info when I right-click on a job and run the script? It seems like I have to pass information between RepositoryUtils, ClientUtils, JobUtils, MonitorUtils, and finally somehow get this result. I have been spending a LOT of time going through this scripting reference and I still can’t figure out how 95% of this stuff is meant to be used because most of it generally lacks a description at all. I think one key thing that is missing in this reference is example code.

For example, I can look under Deadline.Jobs.Job Class Reference and go to “Detailed Description,” all it says is “A job.” What am I supposed to take from that? I think putting a few snippets of example usage would be beneficial for everybody, or at least a “detailed description” for those of us that aren’t necessarily coding Gurus.

I’m sorry about the lack of example code in our scripting reference. We have a GitHub site with a few code examples, but obviously it needs more:
github.com/ThinkboxSoftware/Deadline

We also need to make the site more visible, since right now I think Edwin just points people there when they are looking for examples.

For your script, you’ll want to use RepositoryUtils.GetJobTasks to get a collection of the job’s tasks. You can then iterate through them and get their properties. For example:

myTasks = RepositoryUtils.GetJobTasks( myJob, True )
for task in myTasks:
    totalTaskTimeSeconds += task.TaskTime.TotalSeconds

There is also a JobUtils.CalculateJobStatistics function that returns a JobEntry object with many stats already calculated:

myTasks = RepositoryUtils.GetJobTasks( myJob, True )
jobStats = JobUtils.CalculateJobStatistics( myJob, myTasks )

Hopefully that gets you going, and if you’re willing to share your finished script, we can upload it to GitHub.

If you have any other questions or run into any issues, let us know!

Cheers,
Ryan

I don’t mean to hijack this thread but this brought up something that I’ve been trying to do for a while. I find it really useful to have the auto complete in my script editor because it can help find functionality that I didn’t know I had access to. So I followed the instructions from this page to set up the Python API for Deadline:

thinkboxsoftware.com/deadlin … pythonapi/

Works great. But I noticed in some of the examples and the actual scripts in the Repository that there are some things that I can’t get access to through auto complete. like RepositoryUtils, ClientUtils, JobUtils…etc. My knowledge of setting up a proper dev environment is spotty so I feel I may be missing something.

Thanks for the reply and the examples! I have followed the code you showed me, and I am getting a bit of strange results.

for task in myTasks:
    totalTaskTimeSeconds += task.TaskTime.TotalSeconds

When I run this on an active job, the frames in progress skew the results dramatically. This appears to only give a proper result when the task is marked complete. For example, I have a job that is complete, and if I add up the task render time for the whole job I get something normal like 1800 seconds. If I re-queue a single frame and then try to calculate this again, I get something like 922337205361.0 seconds. Should I be checking a task’s status before calculating this, or is this supposed to be working on frames in progress as well? The latter would be ideal so I can also include frames in progress when trying to come up with an ETA.

Ah, yes, you should check the task state. For completed tasks, you can use task.TaskTime.TotalSeconds. For rendering tasks, you’ll have to do this:

repoTime = RepositoryUtils.GetRepositoryDateTime()
for task in myTasks:
    if task.TaskStatus == "Completed":
        totalTaskTimeSeconds += task.TaskTime.TotalSeconds
    else if task.TaskStatus == "Rendering":
        totalTaskTimeSeconds += repoTime.Subtract(task.TaskStartTime).TotalSeconds

Note that RepositoryUtils.GetRepositoryDateTime() wasn’t introduced until 6.2, but I’m pretty sure you guys are already running 6.2.

Cheers,
Ryan

Yeah now we’re talking! I’m going to do this now. Thanks again!

Privacy | Site terms | Cookie preferences