Use JobBatchName in a script

Hi,

I’d like to use the JobBatchName to check if the jobs in a certain batch are finished, is there a way to get all the jobs under a batch using the JobBatchName?

thanks,
Aamir

No, BatchName is just a UI-level grouping mechanism which uses a Job property to optionally combine jobs in the Monitor. But it is not handled as an internal hierarchy under the hood, so there are no methods to get Jobs by their BatchName.
Your only choice is to get all Jobs from the Database, loop through them, and collect the ones that have the matching BatchName value.

Unless I am missing something…

You’re not missing anything. I just wanted to check if this functionality existed (I figured it wasn’t) but I guess we’ll work around it in a different way. Looping through all jobs may not be an option due to job volume, unless there’s an easy way to loop through the most recent jobs?

edit: how taxing is looping through all jobs?

I did a quick test, and I am getting about 50,000 to 100,000 jobs per second. However, I had only about 100 jobs on the queue, so it is possible my calculations were off.

So if you are one of those companies that keep 100,000 jobs in the Queue, a scan should take around a second. In that code, I collected a dict with all Batch Names as keys, so after that you could access any Batch and its list of Jobs from that cache… If new jobs are added, you can rescan in a second or two.

from Deadline.Scripting import *
import time
from DeadlineUI.Controls.Scripting.DeadlineScriptDialog import DeadlineScriptDialog

########################################################################
## Main Function Called By Deadline
########################################################################
def __main__(*args):
    scriptDialog = DeadlineScriptDialog()
    scriptDialog.SetSize(200, 100)
    scriptDialog.SetTitle( "Scan Batch Names" )
    scriptDialog.AddGrid()
    testButton = scriptDialog.AddControlToGrid( "ScanButton", "ButtonControl", "Scan Jobs", 0, 1, expand=True )
    testButton.ValueModified.connect(scanFunction)
    scriptDialog.EndGrid()
    scriptDialog.ShowDialog( True )
    
########################################################################
## GUI Controls Event Handler Functions
########################################################################    

def scanFunction():
    totalStartTime = time.time()
    jobBatchNames = dict()
    allJobs = RepositoryUtils.GetJobs(True)
    for aJob in allJobs:
        theBatchName = aJob.BatchName
        if not theBatchName in jobBatchNames:
            jobBatchNames[theBatchName] = [aJob]
        else:
            jobBatchNames[theBatchName].append ( aJob )

    print ("TOTAL TIME for %i Jobs: %f seconds, %f Jobs/Second" % (len(allJobs), time.time()-totalStartTime, (len(allJobs)/(time.time()- totalStartTime))) )
    
    for aBatch in jobBatchNames.iterkeys():
        print ("BATCH NAME: [%s]" % (aBatch) )
        for aJob in jobBatchNames[aBatch]:
            print ("\t  [%s]: '%s'" % (aJob.JobId, aJob.JobName))
   
########################################################################
1 Like

thanks, this will get me going :slight_smile:

I’m guessing the line theBatchName = aJob.BatchName is supposed to be aJob.JobBatchName

Why would you think that?

https://docs.thinkboxsoftware.com/products/deadline/10.1/2_Scripting%20Reference/class_deadline_1_1_statistics_1_1_job_entry.html#ac1746dc52b35c719429f7bb451ee19f6

1 Like

Oh, I see. I was looking here:
https://docs.thinkboxsoftware.com/products/deadline/10.1/2_Scripting%20Reference/class_deadline_1_1_jobs_1_1_job.html#a677c43617e6af1b011c829653c1620b0

I’m guessing that’ll give me the wrong response? Should I just be using BatchName like your implementation?

No, you don’t have to change, both work the same.
The key/value in the Job metadata is called “BatchName=…” (if you look at the Submission Params).

Most Job Properties can be specified with or without the “Job” prefix. For example, you can have the last line of my script look like

        print ("\t  [%s]: '%s'" % (aJob.JobId, aJob.Name))

and the JobName will be printed. But you cannot change JobId, it is an exception.

1 Like

Cool thanks! Good to know :slightly_smiling_face:

Privacy | Site terms | Cookie preferences