Skip to content

Commit

Permalink
Merge pull request #83 from ericmehl/useDispatchJobName
Browse files Browse the repository at this point in the history
Use dispatch job name
  • Loading branch information
ericmehl authored Aug 17, 2024
2 parents 3167bc1 + 184592a commit 216bbe3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Fixed bug that prevented context variables from being substituted into GafferDeadline plugs. (#79)
- Added `extraDeadlineSettings` and `extraEnvironmentVariables` plugs. These can be set by an expression to add arbitrary numbers of Deadline settings and environment variables. Entries in these plugs will take precedence over identically named settings / variables in the `deadlineSettings` and `environmentVariables` plugs.
- *Breaking change* : Changed job names to be `${dispatcher.jobName}.${taskNodeName}`.
- Added `batchName` plug to allow easy customization of the batch name. Previously it would be set to the dispatcher's `jobName` plug value unless overridden in `deadlineSettings`. The default value is the same as dispatchers' `jobName` default value, so unless you change the `batchName` plug value, batches will be named the same as previously.

# 0.58.0.0b3
- API : Added `GafferDeadlineJob.environmentVariables()` method.
Expand Down
37 changes: 19 additions & 18 deletions python/GafferDeadline/DeadlineDispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ def _doDispatch(self, rootBatch):

dispatchData["scriptNode"].serialiseToFile(dispatchData["scriptFile"])

context = Gaffer.Context.current()
dispatchData["deadlineBatch"] = (
context.substitute(self["jobName"].getValue()) or "untitled"
)
with Gaffer.Context.current() as c:
dispatchData["dispatchJobName"] = self["jobName"].getValue()

rootDeadlineJob = GafferDeadline.GafferDeadlineJob(rootBatch.node())
rootDeadlineJob.setAuxFiles([dispatchData["scriptFile"]])
Expand Down Expand Up @@ -226,36 +224,38 @@ def __submitDeadlineJob(self, deadlineJob, dispatchData):

with Gaffer.Context(deadlineJob.getContext()) as c:
jobInfo = {
"Name": gafferNode.relativeName(dispatchData["scriptNode"]),
"Name": (
"{}{}{}".format(
dispatchData["dispatchJobName"],
"." if dispatchData["dispatchJobName"] else "",
gafferNode.relativeName(dispatchData["scriptNode"]),
)
),
"Frames": frameString,
"ChunkSize": chunkSize,
"Plugin": "Gaffer" if not isinstance(
gafferNode,
GafferDeadline.DeadlineTask
) else gafferNode["plugin"].getValue(),
"BatchName": dispatchData["deadlineBatch"],
"Comment": c.substitute(deadlinePlug["comment"].getValue()),
"Department": c.substitute(deadlinePlug["department"].getValue()),
"Pool": c.substitute(deadlinePlug["pool"].getValue()),
"SecondaryPool": c.substitute(
deadlinePlug["secondaryPool"].getValue()
),
"Group": c.substitute(deadlinePlug["group"].getValue()),
"BatchName": deadlinePlug["batchName"].getValue(),
"Comment": deadlinePlug["comment"].getValue(),
"Department": deadlinePlug["department"].getValue(),
"Pool": deadlinePlug["pool"].getValue(),
"SecondaryPool": deadlinePlug["secondaryPool"].getValue(),
"Group": deadlinePlug["group"].getValue(),
"Priority": deadlinePlug["priority"].getValue(),
"TaskTimeoutMinutes": int(deadlinePlug["taskTimeout"].getValue()),
"EnableAutoTimeout": deadlinePlug["enableAutoTimeout"].getValue(),
"ConcurrentTasks": deadlinePlug["concurrentTasks"].getValue(),
"MachineLimit": deadlinePlug["machineLimit"].getValue(),
machineListType: c.substitute(
deadlinePlug["machineList"].getValue()
),
"LimitGroups": c.substitute(deadlinePlug["limits"].getValue()),
machineListType: deadlinePlug["machineList"].getValue(),
"LimitGroups": deadlinePlug["limits"].getValue(),
"OnJobComplete": deadlinePlug["onJobComplete"].getValue(),
"InitialStatus": initialStatus,
}

auxFiles = deadlineJob.getAuxFiles() # this will already have substitutions included
auxFiles += [c.substitute(f) for f in deadlinePlug["auxFiles"].getValue()]
auxFiles += [f for f in deadlinePlug["auxFiles"].getValue()]
deadlineJob.setAuxFiles(auxFiles)

for output in deadlinePlug["outputs"].getValue():
Expand Down Expand Up @@ -485,6 +485,7 @@ def _setupPlugs(parentPlug):
return

parentPlug["deadline"] = Gaffer.Plug()
parentPlug["deadline"]["batchName"] = Gaffer.StringPlug(defaultValue="${script:name}")
parentPlug["deadline"]["comment"] = Gaffer.StringPlug()
parentPlug["deadline"]["department"] = Gaffer.StringPlug()
parentPlug["deadline"]["pool"] = Gaffer.StringPlug()
Expand Down
41 changes: 41 additions & 0 deletions python/GafferDeadlineTest/DeadlineDispatcherTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,47 @@ def testExtra(self):
self.assertEqual(jobs[0].getEnvironmentVariables()["Index"], "0")
self.assertEqual(jobs[0].getEnvironmentVariables()["ARNOLD_ROOT"], "/arnoldRoot")

def testName(self):
s = Gaffer.ScriptNode()

s["n"] = GafferDispatchTest.LoggingTaskNode()

s["d"] = GafferDeadline.DeadlineDispatcher()
s["d"]["jobsDirectory"].setValue(self.temporaryDirectory() / "testJobDirectory")
s["d"]["preTasks"][0].setInput(s["n"]["task"])

with mock.patch(
"GafferDeadline.DeadlineTools.submitJob",
return_value=("testID", "testMessage")
):
jobs = self.__job([s["n"]], dispatcher=s["d"])

self.assertEqual(jobs[0].getJobProperties()["Name"], "n")

s["d"]["jobName"].setValue("Harvey")
with mock.patch(
"GafferDeadline.DeadlineTools.submitJob",
return_value=("testID", "testMessage")
):
jobs = self.__job([s["n"]], dispatcher=s["d"])

self.assertEqual(jobs[0].getJobProperties()["Name"], "Harvey.n")

s["n"]["dispatcher"]["deadline"]["extraDeadlineSettings"].setValue(
IECore.CompoundObject(
{
"Name": IECore.StringData("LittleDebbie"),
}
)
)
with mock.patch(
"GafferDeadline.DeadlineTools.submitJob",
return_value=("testID", "testMessage")
):
jobs = self.__job([s["n"]], dispatcher=s["d"])

self.assertEqual(jobs[0].getJobProperties()["Name"], "LittleDebbie")


if __name__ == "__main__":
unittest.main()
7 changes: 7 additions & 0 deletions python/GafferDeadlineUI/DeadlineDispatcherUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@

],

"dispatcher.deadline.batchName": [
"description",
"""
The name of the Deadline batch for this job.
"""
],

"dispatcher.deadline.comment": [
"description",
"""
Expand Down

0 comments on commit 216bbe3

Please sign in to comment.