Event script - output job's data

Hi,
I’m trying to output the completed job information so that we could build our own tools around it.
The data I’m after is the same data you’ll get when using the “Farm Status Reports” tool.
I’m aware of the fact that Deadline already create this data, but I’m looking to mirror it to our specific folders, for our specific workflows.

Because I want this data on job completion, an event script is the first thing that comes to mind, but unfortunately I can’t find the proper function to get the data.
I can get some of it using the Deadline.Jobs.Job class, but I’m also looking for the rest of it (Average Frame Time, CPU Usage, etc.).
Those seem to be in the Deadline.Statistics.JobEntry class, but it looks like I’m not using it properly…

This is the test event script:

[code]from System.IO import *
from System.Text import *

from Deadline.Events import *
from Deadline.Scripting import *
from Deadline.Reports import *
from Deadline.Statistics import *

def GetDeadlineEventListener():
return MyEvent()

class MyEvent (DeadlineEventListener):

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

def OnJobFinished( self, job ):
    outputFilenames = job.JobOutputFileNames
    for i in range( 0, len(outputFilenames) ):
        jobTaskCollection = RepositoryUtils.GetJobTasks(job, True)
        jobEntry = JobUtils.CalculateJobStatistics(  job, jobTaskCollection )[/code]

This code errors out saying “Event Error (OnJobFinished): can not create two instances of DeadlineApplicationManager”.

Any insight you have on the matter will be appreciated.
Thanks.

Hmmm, it seems that particular function is expecting to be run in the context of the Deadline Monitor, not sure why; it should be able to run from anywhere, since you’re specifying the Job. We’ll make sure to get that fixed for future versions :slight_smile:

In the meantime, you can achieve mostly the same thing just by doing this:

from System import DateTime
[...]

    def OnJobFinished( self, job ):
        jobTaskCollection = RepositoryUtils.GetJobTasks( job, True )
        jobEntry = JobEntry(  job, jobTaskCollection, DateTime.Now )

Note that I also removed the ‘for’ loop you have in there, since it’s not necessary to create one of these per output like you seemed to be doing.

The above code achieves the same thing, but doesn’t pull in “Wasted Error Time” and “Wasted Requeue Time”. If you care about those, you’ll have to pull in reports and make the calculations yourself like so:

from System import DateTime, TimeSpan
[...]

    def OnJobFinished( self, job ):
        jobTaskCollection = RepositoryUtils.GetJobTasks( job, True )
        jobEntry = JobEntry(  job, jobTaskCollection, DateTime.Now )

        errorTime = TimeSpan.Zero
        requeueTime = TimeSpan.Zero

        reports = RepositoryUtils.GetJobReports( job.JobId )
        for report in reports.GetRequeueReports():
            requeueTime = requeueTime.Add( report.TaskTimeElapsed )

        for report in reports.GetErrorReports():
            errorTime = errorTime.Add( report.TaskTimeElapsed )
            
        jobEntry.WastedErrorTime = errorTime
        jobEntry.WastedRequeueTime = requeueTime

Hope this helps!

Cheers,
Jon

Thanks Jon, that helps a lot! :slight_smile: