Skip to content

Commit 36f32fd

Browse files
Update CueJobMonitorTree only with new data (#1128)
* Update CueJobMonitorTree only with new data Fixed processUpdate to only update in mem dict self._items when "new" jobs are retrieved during the API call. Calling API every 22 seconds with large number of jobs bogs down the gui. Fixed _getUpdate to include the root group and its' associated jobs, this fn returned a different count then the in mem ds. Fixed the recursive fn __getNestedIds, had previously returned only groups and not the associated jobs, so when processUpdate compared the len() of what is in self._items vs what was last retrieved ie current == set(rpcObjects[1]) line 417, it was never the same and continuously tried rebuilding self._items for each interval. * Fix Pylint errors * Fix Pylint errors * Fix method signature Pylint/unittests * Fix Pylint, removed unused import
1 parent 64b382c commit 36f32fd

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

cuegui/cuegui/CueJobMonitorTree.py

+23-25
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import opencue
3232
import opencue.compiled_proto.job_pb2
3333
import opencue.wrappers.group
34-
from opencue.wrappers.job import Job
3534

3635
import cuegui.AbstractTreeWidget
3736
import cuegui.AbstractWidgetItem
@@ -370,7 +369,7 @@ def getShowNames(self):
370369
return list(self.__shows.keys())
371370

372371
def __getCollapsed(self):
373-
return [item.rpcObject for item in list(self._items.values()) if not item.isExpanded()]
372+
return [item.rpcObject.id() for item in list(self._items.values()) if not item.isExpanded()]
374373

375374
def __setCollapsed(self, collapsed):
376375
self.expandAll()
@@ -384,13 +383,19 @@ def _getUpdate(self):
384383
@return: List that contains updated nested groups and a set of all
385384
updated item ideas"""
386385
self.currtime = time.time()
386+
allIds = []
387387
try:
388388
groups = [show.getJobWhiteboard() for show in self.getShows()]
389389
nestedGroups = []
390390
allIds = []
391391
for group in groups:
392+
# add jobs and parent group to match self._items
393+
allIds.append(group.id)
394+
allIds.extend(group.jobs)
392395
nestedGroups.append(opencue.wrappers.group.NestedGroup(group))
393-
allIds.extend(self.__getNestedIds(group))
396+
# pylint: disable=no-value-for-parameter
397+
allIds.extend(self.__getNestedIds(group, updated=[]))
398+
# pylint: enable=no-value-for-parameter
394399
except opencue.exception.CueException as e:
395400
list(map(logger.warning, cuegui.Utils.exceptionOutput(e)))
396401
return None
@@ -411,8 +416,9 @@ def _processUpdate(self, work, rpcObjects):
411416
try:
412417
current = set(self._items.keys())
413418
if current == set(rpcObjects[1]):
414-
# Only updates
415-
self.__processUpdateHandleNested(self.invisibleRootItem(), rpcObjects[0])
419+
# Only updates if return rpcObjects doesn't equal current _items
420+
collapsed = self.__getCollapsed()
421+
self.__setCollapsed(collapsed)
416422
self.redraw()
417423
else:
418424
# (Something removed) or (Something added)
@@ -431,25 +437,20 @@ def _processUpdate(self, work, rpcObjects):
431437
finally:
432438
self._itemsLock.unlock()
433439

434-
def __getNestedIds(self, group):
435-
"""Returns all the ids founds in the nested list
440+
def __getNestedIds(self, group, updated):
441+
"""Returns all the ids founds in the nested list including
442+
group and job ids.
436443
@type group: job_pb2.Group
437-
@param group: A group that can contain groups and/or jobs
444+
@param group: A group that can contain groups and their associated jobs
438445
@rtype: list
439446
@return: The list of all child ids"""
440-
updated = []
441-
for innerGroup in group.groups.nested_groups:
442-
updated.append(innerGroup.id)
443-
444-
# If group has groups, recursively call this function
445-
for g in innerGroup.groups.nested_groups:
446-
updated_g = self.__getNestedIds(g)
447-
if updated_g:
448-
updated.extend(updated_g)
449-
450-
# If group has jobs, update them
451-
for jobId in innerGroup.jobs:
452-
updated.append(jobId)
447+
updated = updated if updated else []
448+
if group.groups.nested_groups:
449+
for g in group.groups.nested_groups:
450+
updated.append(g.id)
451+
if g.jobs:
452+
updated.extend(g.jobs)
453+
self.__getNestedIds(g, updated)
453454

454455
return updated
455456

@@ -477,11 +478,8 @@ def __processUpdateHandleNested(self, parent, groups):
477478
for nestedGroup in group.data.groups.nested_groups]
478479
self.__processUpdateHandleNested(groupItem, nestedGroups)
479480

480-
# empty list will return all jobs on the farm
481-
# only search if list has jobs
482481
if group.data.jobs:
483-
jobSeq = opencue.search.JobSearch.byOptions(id=list(group.data.jobs)).jobs
484-
jobsObject = [Job(j) for j in jobSeq.jobs]
482+
jobsObject = opencue.api.getJobs(id=list(group.data.jobs))
485483

486484
for job in jobsObject:
487485
try:

0 commit comments

Comments
 (0)