From 60e6953b9440aa6d3a3c98a6c00947cc6c7a395f Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 28 May 2013 22:40:06 -0700 Subject: [PATCH 1/4] Add a get many attr/s and join helper functions. --- taskflow/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/taskflow/utils.py b/taskflow/utils.py index 730bc817..6bc2c5e0 100644 --- a/taskflow/utils.py +++ b/taskflow/utils.py @@ -24,6 +24,18 @@ import time LOG = logging.getLogger(__name__) +def join(itr, with_what=","): + pieces = [str(i) for i in itr] + return with_what.join(pieces) + + +def get_many_attr(obj, *attrs): + many = [] + for a in attrs: + many.append(getattr(obj, a, None)) + return many + + def await(check_functor, timeout=None): if timeout is not None: end_time = time.time() + max(0, timeout) From 9fc370815000b46a8a569465ae5de0ea8376d710 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 28 May 2013 22:40:31 -0700 Subject: [PATCH 2/4] Add a major/minor version. --- taskflow/task.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/taskflow/task.py b/taskflow/task.py index 51601101..32d99231 100644 --- a/taskflow/task.py +++ b/taskflow/task.py @@ -18,6 +18,8 @@ import abc +from taskflow import utils + class Task(object): """An abstraction that defines a potential piece of work that can be @@ -33,9 +35,14 @@ class Task(object): # An *immutable* output 'resource' name set this task # produces that other tasks may depend on this task providing. self.provides = set() + # This identifies the version of the task to be ran which + # can be useful in resuming older versions of tasks. Standard + # major, minor version semantics apply. + self.version = (1, 0) def __str__(self): - return "Task: %s" % (self.name) + return "Task: %s v%s" % (self.name, utils.join(self.version, + with_what=".")) @abc.abstractmethod def __call__(self, context, *args, **kwargs): From a78a4338b54bd94df5052239acce49e53204634f Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 28 May 2013 22:40:48 -0700 Subject: [PATCH 3/4] 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. --- taskflow/job.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/taskflow/job.py b/taskflow/job.py index 91873409..4d809b35 100644 --- a/taskflow/job.py +++ b/taskflow/job.py @@ -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): From ee550bab5ab6e8930d7518aa094b33fb234ac25d Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 28 May 2013 22:46:22 -0700 Subject: [PATCH 4/4] Fix spacing --- taskflow/job.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taskflow/job.py b/taskflow/job.py index 4d809b35..cb1b6aee 100644 --- a/taskflow/job.py +++ b/taskflow/job.py @@ -39,9 +39,9 @@ def task_and_state(task, state): # 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__') + '__module__', + '__name__', + '__version__') if a is not None] if not name_pieces: # Ok, unsure what this task is, just use whatever its string