diff --git a/taskflow/__init__.py b/taskflow/__init__.py index ba7bbbc..8a8f8c4 100644 --- a/taskflow/__init__.py +++ b/taskflow/__init__.py @@ -1,5 +1,5 @@ __title__ = "Taskflow" -__version__ = "0.2.1" +__version__ = "0.2.2" from .flow import * # noqa from .tasks import * # noqa diff --git a/taskflow/tasks.py b/taskflow/tasks.py index e63b778..8cbc6f4 100644 --- a/taskflow/tasks.py +++ b/taskflow/tasks.py @@ -1,4 +1,5 @@ import sys +from datetime import datetime from taskflow.defaults import Defaults from taskflow.type_helpers import function_from_string, function_to_string, type_to_string @@ -192,6 +193,8 @@ def __init__(self, func=None, args=None, max_runs=None, needs_prev_result=True, super().__init__(max_runs=max_runs, needs_prev_result=needs_prev_result, name=name) self._func = func self._args = args or [] + self._execution_start_time = None + self._execution_delta_time = None @property def func_name(self): @@ -201,6 +204,10 @@ def func_name(self): def args(self): return self._args + @property + def execution_delta_time(self): + return self._execution_delta_time + def run(self, **kwargs): # overriding args with the prev result # use kwargs for persistent parameters to all Tasks @@ -209,6 +216,7 @@ def run(self, **kwargs): self._runs += 1 try: + self._execution_start_time = datetime.now() self._result = self._func(*args, **kwargs) self._status = self.STATUS_COMPLETE self._error = None @@ -217,6 +225,8 @@ def run(self, **kwargs): self._status = self.STATUS_HALTED if self._runs >= self.max_runs else self.STATUS_PENDING self._error = ex self._exc_info = sys.exc_info() + finally: + self._execution_delta_time = (datetime.now() - self._execution_start_time).total_seconds() def __str__(self): return self._name if self._name else f"{function_to_string(self._func)}:{self._args}"