Skip to content

Commit

Permalink
Save correct datetime format to the DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Feb 1, 2024
1 parent 433d80b commit 8449871
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
19 changes: 7 additions & 12 deletions cylc/flow/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
TASK_STATUS_FAILED,
TASK_STATUS_SUCCEEDED,
)
from cylc.flow.wallclock import get_current_time_string
from cylc.flow.wallclock import (
get_current_time_string, get_unix_time_from_time_string)

from metomi.isodatetime.parsers import DurationParser, TimePointParser
from metomi.isodatetime.parsers import DurationParser

if TYPE_CHECKING:
from queue import Queue
Expand Down Expand Up @@ -77,17 +78,11 @@ def __init__(
# repopulating from the DB on workflow restart:
started_time = itask.summary['started_time']
if started_time is None and db_mgr:
started_time = int(
TimePointParser()
.parse(
db_mgr.pub_dao.select_task_job(
*itask.tokens.relative_id.split("/")
)["time_submit"]
)
.seconds_since_unix_epoch
)
started_time_str = db_mgr.pub_dao.select_task_job(
*itask.tokens.relative_id.split("/"))["time_submit"]
started_time = get_unix_time_from_time_string(
started_time_str)
itask.summary['started_time'] = started_time

self.timeout = started_time + self.simulated_run_length


Expand Down
4 changes: 3 additions & 1 deletion cylc/flow/task_job_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
)
from cylc.flow.wallclock import (
get_current_time_string,
get_time_string_from_unix_time,
get_utc_mode
)
from cylc.flow.cfgspec.globalcfg import SYSPATH
Expand Down Expand Up @@ -998,6 +999,7 @@ def _set_retry_timers(
def _simulation_submit_task_jobs(self, itasks, workflow):
"""Simulation mode task jobs submission."""
now = time()
now_str = get_time_string_from_unix_time(now)
for itask in itasks:
itask.summary['started_time'] = now
itask.mode_settings = ModeSettings(
Expand All @@ -1018,7 +1020,7 @@ def _simulation_submit_task_jobs(self, itasks, workflow):
itask, INFO, TASK_OUTPUT_SUBMITTED,
)
self.workflow_db_mgr.put_insert_task_jobs(
itask, {'time_submit': get_current_time_string()})
itask, {'time_submit': now_str})

return itasks

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_false_if_not_running(
id='fail-no-submits'),
)
)
def test_fail_once(sim_time_check_setup, itask, point, results):
def test_fail_once(sim_time_check_setup, itask, point, results, monkeypatch):
"""A task with a fail cycle point only fails
at that cycle point, and then only on the first submission.
"""
Expand All @@ -183,7 +183,8 @@ def test_fail_once(sim_time_check_setup, itask, point, results):
itask = schd.pool.get_task(
ISO8601Point(point), itask)

for result in results:
for i, result in enumerate(results):
itask.try_timers['execution-retry'].num = i - 1
schd.task_job_mgr._simulation_submit_task_jobs(
[itask], schd.workflow)
assert itask.mode_settings.sim_task_fails is result
Expand Down Expand Up @@ -319,7 +320,7 @@ async def test_simulation_mode_settings_restart(
# Set the start time in the database to 0 to make the
# test simpler:
schd.workflow_db_mgr.put_insert_task_jobs(
itask, {'time_submit': '19700101T0000Z'})
itask, {'time_submit': '1970-01-01T00:00:00Z'})
schd.workflow_db_mgr.process_queued_ops()

# Set the current time:
Expand Down

0 comments on commit 8449871

Please sign in to comment.