Schedule a job while its running (Inside the plugin)

Hi,

I have the following situation in our Studio:

We have two repositories. On each is the same job (one is transferred to the other). The original job (lets call it place holder) is blacklisted with all slaves and will just represent the transferred render job in the other repository. I wrote an application plugin (update job) which is only updating the render progress to the place holder job. That works fine, but the update job is running the whole time. My idea is to change the schedule time each time when the job itself is running. So when the update job runs, it changes its schedule start time to X minutes in the future. The problem is that it looks like that I can’t change the job properties in the plugin itself.

Example:

Job = self.GetJob()

Job.JobScheduledType="Once"

self.LogInfo(Job.JobScheduledType) # <- Check it

The system print was right and it the job schedule type is changed, but when I check the result with the job properties in the Deadline Monitor nothing was changed. Why can’t I change the Schedule stuff inside the plugin?

I also want to change schedule start date time. The object property Job.JobScheduledStartDateTime is expecting an object called DateTime and is from type <class ‘System.DateTime’>, but i can’t find any information in the documentation to convert my date into this object (The class System is not documented).
I also tried to set the property with a string in the expected format y/m/d H:M:S, but it doens’t work:

import datetime

interval = int(self.GetConfigEntryWithDefault( "RepeatInterval", str(2) ))

newTime = datetime.datetime.now() +  datetime.timedelta(minutes=interval)
Job.JobScheduledStartDateTime = newTime.strftime("%Y/%m/%d %H:%M:%S")

The following Error appears:

[code]Error in RenderTasks: TypeError : ‘str’ value cannot be converted to System.DateTime (Python.Runtime.PythonException)
File “none”, line 96, in RenderTasks

at Deadline.Plugins.ScriptPlugin.RenderTasks(String taskId, Int32 startFrame, Int32 endFrame, String& outMessage, AbortLevel& abortLevel)
[/code]

How do I convert my time into the expected format? Or is there a better way to let a job pause for a defined time, after it was running?

Thanks,
Michael

Hello Michael,

I am not sure on this, but I am wondering if you are changing the status of the job(rendering to suspended) before you set the start date and time via that command? I’ll have to check with some folks for clarity on the best method to use.

I never change the status of the job to suspended, because the job has to run to make the change to its start date to a later time. I don’t want to change the start date of an other job, I want to change the schedule of the job itself inside its job plugin.
Maybe it helps if you see where I trying to use that code inside the plugin:

# [...]

class UpdateJob (DeadlinePlugin):

    # [...] 

    def RenderTasks(self):
        dummyJobId  = self.GetPluginInfoEntry( "DummyJob" )
        dummyJob    = RepositoryUtils.GetJob( dummyJobId, True )

        Job         = self.GetJob()
        interval    = int(self.GetConfigEntryWithDefault( "RepeatInterval", str(2) ))

        Job.JobScheduledType="Once" # It seems that it it doesn't affect the job itself.. Why?

        # [...]
        # Update Dummy Job... works fine
        # JobDone = False if ... job still running else True

        newTime = datetime.datetime.now() +  datetime.timedelta(minutes=interval)
        Job.JobScheduledStartDateTime = newTime  # ? or newTime..strftime("%Y/%m/%d %H:%M:%S") but needs to be DateTime

        if not JobDone:
            self.AbortRender("\n\t # Update is not Done!!\n\t ~ Requeue Job~",ManagedProcess.AbortLevel.Minor)
        # [...]

Everything works fine except the schedule stuff for the job itself.
It looks like, that I am not able to change the job properties while it is running.

If you or anyone else find a solution that the job will not run constantly (dosn’t have to be done with schedule the start dateTime), please let me know…

Hi Michael,

In order to save the changes to the job’s properties, you must call RepositoryUtils.SaveJob(). If you are running Deadline 7.0 or earlier, you will probably also need to reset a hidden property called ScheduledLastDateTime or the job will likely never start again (this is something we fixed in 7.1, which is currently in beta). Finally, I think you’ll need to put the job back in the Pending state so that it can be released at the appropriate time again.

The DateTime object is actually a .NET object:
msdn.microsoft.com/en-us/librar … 10%29.aspx

We use Python.NET to all us to mix Python and .NET code.

Another thing you can change is how you get the interval value. You can get it as an integer, rather than getting it as a string and casting it to an integer.

I took your example code and applied all the changes mentioned above. I haven’t tested any of this, but hopefully this gets you closer to a working solution.

Cheers,
Ryan

from System import DateTime ## NEW
# [...]

class UpdateJob (DeadlinePlugin):

    # [...] 
    def RenderTasks(self):
        dummyJobId  = self.GetPluginInfoEntry( "DummyJob" )
        dummyJob    = RepositoryUtils.GetJob( dummyJobId, True )

        Job         = self.GetJob()
        #interval    = int(self.GetConfigEntryWithDefault( "RepeatInterval", str(2) ))
        interval    = self.GetIntegerConfigEntryWithDefault( "RepeatInterval", 2 ) ## NEW

        Job.JobScheduledType="Once" # It seems that it it doesn't affect the job itself.. Why?

        # [...]
        # Update Dummy Job... works fine
        # JobDone = False if ... job still running else True

        #newTime = datetime.datetime.now() +  datetime.timedelta(minutes=interval)
        #Job.JobScheduledStartDateTime = newTime  # ? or newTime..strftime("%Y/%m/%d %H:%M:%S") but needs to be DateTime
        Job.JobScheduledStartDateTime = DateTime.Now.AddMinutes(interval) ## NEW
        Job.ScheduledLastDateTime = DateTime.MinValue ## NEW

        RepositoryUtils.SaveJob( Job ) ## NEW
        RepositoryUtils.PendJob( Job ) ## NEW

        if not JobDone:
            self.AbortRender("\n\t # Update is not Done!!\n\t ~ Requeue Job~",ManagedProcess.AbortLevel.Minor)
        # [...]

Hi Ryan,

thank you very much!! It works fine now, exactly how I wanted it to be.

Cheers,
Michael

Awesome! Glad to hear it works.

Cheers,
Ryan