Skip to content

Commit

Permalink
modified executiongraph to round datetimes to nearest second
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher R. Krenn authored and FrankD412 committed May 17, 2020
1 parent c5d1f69 commit 5051b2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions maestrowf/datastructures/core/executiongraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from maestrowf.datastructures.dag import DAG
from maestrowf.datastructures.environment import Variable
from maestrowf.interfaces import ScriptAdapterFactory
from maestrowf.utils import create_parentdir, get_duration
from maestrowf.utils import create_parentdir, get_duration, round_datetime_seconds

LOGGER = logging.getLogger(__name__)
SOURCE = "_source"
Expand Down Expand Up @@ -140,7 +140,7 @@ def mark_submitted(self):
self.status)
self.status = State.PENDING
if not self._submit_time:
self._submit_time = datetime.now()
self._submit_time = round_datetime_seconds(datetime.now())
else:
LOGGER.warning(
"Cannot set the submission time of '%s' because it has "
Expand All @@ -155,7 +155,7 @@ def mark_running(self):
self.status)
self.status = State.RUNNING
if not self._start_time:
self._start_time = datetime.now()
self._start_time = round_datetime_seconds(datetime.now())

def mark_end(self, state):
"""
Expand All @@ -170,7 +170,7 @@ def mark_end(self, state):
self.status)
self.status = state
if not self._end_time:
self._end_time = datetime.now()
self._end_time = round_datetime_seconds(datetime.now())

def mark_restart(self):
"""Mark the end time of the record."""
Expand Down
17 changes: 16 additions & 1 deletion maestrowf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
from six.moves.urllib.request import urlopen
from six.moves.urllib.error import HTTPError, URLError
import time
import datetime

LOGGER = logging.getLogger(__name__)


def get_duration(time_delta):
"""
Covert durations to HH:MM:SS format.
Convert durations to HH:MM:SS format.
:params time_delta: A time difference in datatime format.
:returns: A formatted string in HH:MM:SS
Expand All @@ -58,6 +59,20 @@ def get_duration(time_delta):
return "{:d}d:{:02d}h:{:02d}m:{:02d}s" \
.format(days, hours, minutes, seconds)

def round_datetime_seconds(input_datetime):
"""
Round datetime to the nearest whole second.
:params input_datetime: A datetime in datatime format.
:returns: ``input_datetime`` rounded to the nearest whole second
"""
new_datetime = input_datetime

if new_datetime.microsecond >= 500000:
new_datetime = new_datetime + datetime.timedelta(seconds=1)

return new_datetime.replace(microsecond=0)


def generate_filename(path, append_time=True):
"""
Expand Down

0 comments on commit 5051b2c

Please sign in to comment.