Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion taskflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "Taskflow"
__version__ = "0.2.1"
__version__ = "0.2.2"

from .flow import * # noqa
from .tasks import * # noqa
10 changes: 10 additions & 0 deletions taskflow/tasks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}"
Expand Down