Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeacock-zenoss committed Jan 2, 2025
1 parent acfbac2 commit aea75eb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
9 changes: 3 additions & 6 deletions Products/Jobber/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from .config import ZenCeleryConfig

_appkey = "zenjobs"
_createdkey = "{}:created".format(_appkey)
_startedkey = "{}:started".format(_appkey)
_finishedkey = "{}:finished".format(_appkey)

_jobkey_template = "{}:job:{{}}".format(_appkey)
_statuskey_template = "{}:status:{{}}".format(_appkey)
Expand Down Expand Up @@ -176,12 +179,6 @@ def search(self, **fields):
:rtype: Iterable[str]
:raises TypError: if an unsupported value type is given for a field
"""

# 'created', 'started', 'finished' fields are indexed by sorted-set
# keys of the same names.
# 'name', 'status', and 'userid' fields are indexed by set keys where
# each name, status, and userid value is its own key.

_verifyfields(fields.keys())

statuses = fields.pop("status", ())
Expand Down
1 change: 0 additions & 1 deletion Products/Jobber/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ def setUp(t):
t.store = JobStore(t.layer.redis)
for jobid, data in t.records.items():
t.store[jobid] = data
# t.layer.redis.hmset("zenjobs:job:%s" % jobid, data)

def tearDown(t):
del t.store
Expand Down
19 changes: 10 additions & 9 deletions Products/Zuul/routers/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,24 @@ def detail(self, jobid):
logfile, content, maxLimit = None, None, None
return {"content": content, "logfile": logfile, "maxLimit": maxLimit}

_validstates = {
"STARTED": "started",
"SUCCESS": "finished",
"PENDING": "created",
"RETRY": "started",
}

def userjobs(self):
results = defaultdict(list)
totals = {}
validstates = {
"STARTED": "started",
"SUCCESS": "finished",
"PENDING": "created",
"RETRY": "started",
}
for job in self.api.getUserJobs(statuses=validstates.keys()):
for job in self.api.getUserJobs(statuses=self._validstates.keys()):
results[job.status].append(job)
# Sort and slice appropriately -- most recent 10 items
for status, jobs in results.iteritems():
try:
jobs.sort(
key=lambda j: getattr(j, validstates[status]),
reverse=True
key=lambda j: getattr(j, self._validstates[status]),
reverse=True,
)
except Exception as ex:
log.warn("Couldn't sort: (%r) %s", ex, ex)
Expand Down

0 comments on commit aea75eb

Please sign in to comment.