Skip to content

Commit a665100

Browse files
Merge pull request #3 from Vectorworks/improvement/task-execution-start-time
[SD-8228] Add execution start time for task
2 parents 8d11302 + aa327f7 commit a665100

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

taskflow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = "Taskflow"
2-
__version__ = "0.2.1"
2+
__version__ = "0.2.2"
33

44
from .flow import * # noqa
55
from .tasks import * # noqa

taskflow/tasks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from datetime import datetime
23

34
from taskflow.defaults import Defaults
45
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,
192193
super().__init__(max_runs=max_runs, needs_prev_result=needs_prev_result, name=name)
193194
self._func = func
194195
self._args = args or []
196+
self._execution_start_time = None
197+
self._execution_delta_time = None
195198

196199
@property
197200
def func_name(self):
@@ -201,6 +204,10 @@ def func_name(self):
201204
def args(self):
202205
return self._args
203206

207+
@property
208+
def execution_delta_time(self):
209+
return self._execution_delta_time
210+
204211
def run(self, **kwargs):
205212
# overriding args with the prev result
206213
# use kwargs for persistent parameters to all Tasks
@@ -209,6 +216,7 @@ def run(self, **kwargs):
209216

210217
self._runs += 1
211218
try:
219+
self._execution_start_time = datetime.now()
212220
self._result = self._func(*args, **kwargs)
213221
self._status = self.STATUS_COMPLETE
214222
self._error = None
@@ -217,6 +225,8 @@ def run(self, **kwargs):
217225
self._status = self.STATUS_HALTED if self._runs >= self.max_runs else self.STATUS_PENDING
218226
self._error = ex
219227
self._exc_info = sys.exc_info()
228+
finally:
229+
self._execution_delta_time = (datetime.now() - self._execution_start_time).total_seconds()
220230

221231
def __str__(self):
222232
return self._name if self._name else f"{function_to_string(self._func)}:{self._args}"

0 commit comments

Comments
 (0)