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): def task_and_state(task, state):
name_pieces = []
try: 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: except AttributeError:
try: pass
name = task.__name__ if not name_pieces:
except AttributeError: # Likely a function and not a task object so let us search for these
name = str(task) # attributes to get a good name for this task.
return "%s:%s" % (name, state) 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): class Claimer(object):