Hi,
I want to get the priority of a job via python script, but the function SlaveInfo().SlaveCurrentJobPriority returns -1. Can someone explain me why? I’m a bit confused.
Thanks in advance!
Mike
Hi,
I want to get the priority of a job via python script, but the function SlaveInfo().SlaveCurrentJobPriority returns -1. Can someone explain me why? I’m a bit confused.
Thanks in advance!
Mike
Hi,
To query a job’s priority we need to first grab an instance of the job object in the python script, then we can start asking it questions like what is it’s priority? So, in a Deadline Python Job Script (right click a job and go to scripts) we could create the code below and save it in a Python script called say; “JobInfo.py” and for each selected job, it will print out some job info. The last line, being what you have asked for:
[code]from Deadline.Scripting import *
from Deadline.Jobs import *
def main( *args ):
selectedJobs = MonitorUtils.GetSelectedJobs()
if len(selectedJobs) > 0:
for job in selectedJobs:
print "Job.JobName: %s" % job.JobName
print "Job.JobId: %s" % job.JobId
print "Job.JobUserName: %s" % job.JobUserName
print "Job.JobPriority: %s" % job.JobPriority[/code]
SlaveInfo().SlaveCurrentJobPriority returns -1 as you are asking what is the priority of the job currently rendering on a slave. If the slave isn’t rendering, I’m guessing it returns -1 to signify this. I’ll have to check this, but I assume if the slave is rendering it does indeed return the correct priority number?
Hope this helps,
Mike
Hi Mike, thanks for your reply! I guess my question was a bit imprecisely, that’s my fault. I’m running a Pre-Job Python script to create a second job out of it and therefore I need to find out the priority of the job at the time the script is executed. First I tried to read it out of the job info file, but the propblem here is that it doesn’t changes if someone changes the priority of the job in the monitor. Because the script is executed on a slave as a job task I was hoping it returns the correct priority at this moment, but apparently it doesn’t. If I check the priority shown on the slave itself while executing the script it shows the value I want to have, so I guess there must be a way to get this!?
Thanks again,
Mike
Hi Mike,
I’m assuming you are using v5? If so, you can use the global function: “GetJob()” to return an instance of the job object and then you can query it for it’s priority:
def __main__( *args ):
job = GetJob()
jobPriority = job.JobPriority
Mike
Yepp, I’m using v5. Sometimes it’s so easy… thanks a lot!
But anyway, do you know why the SlaveInfo() function returns -1? I’m just curious.
cheers,
Mike
SlaveInfo().SlaveCurrentJobPriority returns -1 as you are asking what is the priority of the job currently rendering on a slave. If the slave isn’t rendering, I’m guessing it returns -1 to signify this.
Okay, in this case I’m just wondering why the correct priority is shown on the Deadline Slave when it executes the pre job script. But nevermind, it’s working perfect now, thanks for your help!
It’s because SlaveInfo() is the constructor for the SlaveInfo object. So “SlaveInfo().SlaveCurrentJobPriority” is creating a new default instance of a SlaveInfo object and then grabbing the default SlaveCurrentJobPriority value, which is -1.
Cheers,
Makes sense, thanks for the explanation!