Add a better task name algorithm.

This one will incorporate the task name and task version
if the task is backed by the expected task class or if
it is not then we will attempt to examine object for a
few attributes and use those instead.
This commit is contained in:
Joshua Harlow
2013-05-28 22:40:48 -07:00
parent 9fc3708150
commit a78a4338b5

View File

@@ -26,14 +26,28 @@ from taskflow.openstack.common import uuidutils
def task_and_state(task, state):
name_pieces = []
try:
name = task.name
name_pieces.append(task.name)
if isinstance(task.version, (list, tuple)):
name_pieces.append(utils.join(task.version, "."))
else:
name_pieces.append(task.version)
except AttributeError:
try:
name = task.__name__
except AttributeError:
name = str(task)
return "%s:%s" % (name, state)
pass
if not name_pieces:
# Likely a function and not a task object so let us search for these
# attributes to get a good name for this task.
name_pieces = [a for a in utils.get_many_attr(task,
'__module__',
'__name__',
'__version__')
if a is not None]
if not name_pieces:
# Ok, unsure what this task is, just use whatever its string
# representation is.
name_pieces.append(task)
return "%s;%s" % (utils.join(name_pieces, ':'), state)
class Claimer(object):