AWS Thinkbox Discussion Forums

Add Post Job Script via custom Event

Hey, so first off I’m super new to Deadline and not the most experienced programmer aswell.
I want to use a custom event to add a python script as a post job script to each render job submitted. I’ve tried several different attempts but to no avail. There is just nothing happening, not even some Error message in the console.
This is my code so far:

from Deadline.Events import DeadlineEventListener
from Deadline.Jobs import Job

import sys


def GetDeadlineEventListener():
    return SubmitEventTest()

def CleanupDeadlineEventListener(eventListener):
    eventListener.Cleanup()


class SubmitEventTest(DeadlineEventListener):
    def __init__(self):
        if sys.version_info.major == 3:
            super().__init__()
        self.OnJobSubmittedCallback += self.OnJobSubmitted
    
    def Cleanup(self):
        del self.OnJobSubmittedCallback
     
    ## This is called when a job is submitted.
    def OnJobSubmitted(self, job):
        postJobScriptPath = "PathToTheScript\DeadlineRepository10\custom\scripts\Jobs\MyScript.py"
        
        job.AddPostJobScript(postJobScriptPath)
        job.SaveJob()

I also created a .param file just to ensure that the event was enabled:

[State]
Type=Enum
Items=Global Enabled;Opt-In;Disabled
Category=Options
CategoryOrder=0
Index=0
Label=State
Default=Global Enabled
Description=How this event plugin should respond to events.

If someone could nudge me in the right direction of what I’m missing, I’d be super happy - thanks :smiley:

Hello.

I think you need to add:
from Deadline.Scripting import RepositoryUtils

Scripting reference is here (and search for “SetPostJobScript” its parameters are: job, script and “SaveJob(job)”)
https://docs.thinkboxsoftware.com/products/deadline/10.3/2_Scripting%20Reference/class_deadline_1_1_scripting_1_1_repository_utils.html

This older post is still relevant to what you want to accomplish:

Can probably add a self.LogInfo(“Job saved with post-job script.”) so it will be logged.
There are way better coders/pipeline devs on this forum (I’m a sysadmin) , so hopefully one of them will chime in.

2 Likes

Hey Jarak,

thank you very much, that solved my problem already!
I’ve seen the post before too, but I think I had some other bugs in my code because it still didn’t work then.

Just for archival purposes here is the working code

from Deadline.Events import DeadlineEventListener
from Deadline.Scripting import RepositoryUtils

import sys


def GetDeadlineEventListener():
    return SubmitEventTest()

def CleanupDeadlineEventListener(eventListener):
    eventListener.Cleanup()

class SubmitEventTest(DeadlineEventListener):
    def __init__(self):
        if sys.version_info.major == 3:
            super().__init__()
        self.OnJobSubmittedCallback += self.OnJobSubmitted
    
    def Cleanup(self):
        del self.OnJobSubmittedCallback
     
    ## This is called when a job is submitted.
    def OnJobSubmitted(self, job):
        postJobScriptPath = "PathToTheScript\DeadlineRepository10\custom\scripts\Jobs\MyScript.py"
        
        RepositoryUtils.SetPostJobScript(job, postJobScriptPath)
        RepositoryUtils.SaveJob(job)
        self.LogInfo("Job saved with post-job script.")
Privacy | Site terms | Cookie preferences