Skip to content

Commit

Permalink
Catch bad zenjobs task name earlier.
Browse files Browse the repository at this point in the history
ZEN-35109
  • Loading branch information
jpeacock-zenoss committed Oct 22, 2024
1 parent 2592dc9 commit a801868
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
14 changes: 9 additions & 5 deletions Products/Jobber/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,12 @@ def _getByStatusAndType(statuses, jobtype=None):

def _getJobTypeStr(jobtype):
if isinstance(jobtype, type):
return jobtype.name
task = app.tasks.get(str(jobtype))
if not task:
raise ValueError("No such job: {!r}".format(jobtype))
return task.name
name = jobtype.name
else:
task = app.tasks.get(str(jobtype))
if not task:
raise ValueError("No such task: {!r}".format(jobtype))
name = task.name
if name is None:
raise ValueError("zenjobs task name is None: {!r}".format(jobtype))
return name
2 changes: 1 addition & 1 deletion Products/Jobber/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def job(_context, **kw):
if not task.name or task.name not in app.tasks:
try:
registered_task = app.register_task(task)
setattr(registered_task.__class__, 'name', registered_task.name)
registered_task.__class__.name = registered_task.name
except Exception as e:
raise Exception("Task registration failed: %s" % e)

Expand Down
6 changes: 4 additions & 2 deletions Products/Jobber/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from collections import Container, Iterable, Sized

import six

from celery import states as celery_states

from Products.ZenUtils.RedisUtils import getRedisClient
Expand Down Expand Up @@ -101,7 +103,7 @@ class _Any(object):
"""

def __init__(self, *matches):
if not all(isinstance(m, basestring) for m in matches):
if not all(isinstance(m, six.string_types) for m in matches):
raise ValueError(
"All values must be strings %s" % (matches,),
)
Expand Down Expand Up @@ -174,7 +176,7 @@ def search(self, **fields):
for name, match in fields.items():
# Note: check for string first because strings are also
# iterable.
if isinstance(match, basestring):
if isinstance(match, six.string_types):
matchers[name] = match
elif isinstance(match, Iterable):
matchers[name] = _Any(*match)
Expand Down
2 changes: 1 addition & 1 deletion Products/Jobber/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __new__(cls, *args, **kwargs):
summary = getattr(task, "summary", None)
if not summary:
summary = _default_summary.format(task)
setattr(cls, "summary", summary)
cls.summary = summary

task.max_retries = getConfig().get("zodb-max-retries", 5)

Expand Down

0 comments on commit a801868

Please sign in to comment.