Post job script leads to corrupted job

Heyy, with the following code I tried to add a post job script to certain jobs.

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



def GetDeadlineEventListener():
    return MayaScriptEventListener()


def CleanupDeadlineEventListener(eventListener):
    eventListener.Cleanup()


class MayaScriptEventListener(DeadlineEventListener):
    def __init__(self):
        super().__init__()
        self.OnJobSubmittedCallback += self.OnJobSubmitted

    def Cleanup(self):
        del self.OnJobSubmittedCallback

    def OnJobSubmitted(self, job):
        ClientUtils.LogText("in job submitted of maya script\n")
        info_file_path = "C:/path/to/textfile.txt"
        if not os.path.exists(info_file_path):
            with open(info_file_path, "w") as info_file:
                info_file.write(f"created\n")

        script = self.GetConfigEntry("PostJobScript")

        with open(info_file_path, "a") as info_file:
            info_file.write(f"maya script path: {script}\n")

        if "breakdown" in job.JobName:
            RepositoryUtils.SetPostJobScript(job, script)
            RepositoryUtils.SaveJob(job)

            with open(info_file_path, "a") as info_file:
                info_file.write(f"post  job script set\n")

It creates the info_file and writes the right things but when I look at the job in the deadline monitor, it’s queued. The progress though is colored blue like it’s already completed. When I click on it I can see the post job script as a task and the frames. When I suspend the job, it becomes corrupted, then I can repair it, it becomes suspended and then I can resume the job and it works. Why does it have these difficulties in the beginning? What can I do to make it work right when it’s submitted?
Thank you in advance:)

Edit: I already tried to use a OnJobFinished-function and add the post job script there. Then the frames render fine and when they’re finished (marked as completed) the post job script appears as a task but it is immediately also marked as complete even though the post job script wasn’t executed. The job itself is also marked blue as complete but it only says 50% rather than 100% (I only have one other task (the frames) beside the post job script)

1 Like

I’ve got the same problem here: adding a post-job script with Python, and the job gets corrupted afterwards. When I manually add the script, everything works fine. Only instead of using an event plugin, I’m adding it from a JobPreLoad.py in a plugin.

I’m using the same code as you:

job = deadlinePlugin.GetJob()
RepositoryUtils.SetPostJobScript(job, "C:/path/to/UE5_PostJobScript.py")
RepositoryUtils.SaveJob(job)

Hoping someone might have a solution for this.