Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified executiongraph to round datetimes to nearest second #265

Merged
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
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
FrankD412 marked this conversation as resolved.
Show resolved Hide resolved

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