Skip to content

Commit

Permalink
Tweak flow log format.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Jan 25, 2024
1 parent a2ae736 commit a454a06
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
25 changes: 15 additions & 10 deletions cylc/flow/flow_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,36 @@ def stringify_flow_nums(flow_nums: Set[int], full: bool = False) -> str:
Examples:
>>> stringify_flow_nums({})
'(none)'
'(flows=none)'
>>> stringify_flow_nums({1})
''
>>> stringify_flow_nums({1}, True)
'(1)'
'(flows=1)'
>>> stringify_flow_nums({1,2,3})
'(1,2,3)'
'(flows=1,2,3)'
"""
if not full and flow_nums == {1}:
return ""
return (
"("
f"{','.join(str(i) for i in flow_nums) or 'none'}"
")"
)
else:
return (
"(flows="
f"{','.join(str(i) for i in flow_nums) or 'none'}"
")"
)


class FlowMgr:
"""Logic to manage flow counter and flow metadata."""

def __init__(self, db_mgr: "WorkflowDatabaseManager", utc: bool) -> None:
def __init__(
self,
db_mgr: "WorkflowDatabaseManager",
utc: bool = True
) -> None:
"""Initialise the flow manager."""
self.db_mgr = db_mgr
self.flows: Dict[int, Dict[str, str]] = {}
Expand Down Expand Up @@ -156,7 +161,7 @@ def get_flow_num(
)
else:
# Record a new flow.
now_sec = datetime.datetime.now(self._timezone).isoformat(
now_sec = datetime.datetime.now(tz=self._timezone).isoformat(
timespec="seconds"
)
meta = meta or "no description"
Expand Down
3 changes: 0 additions & 3 deletions cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,6 @@ def log_start(self) -> None:

# Note that the following lines must be present at the top of
# the workflow log file for use in reference test runs.
LOG.info(
"Task log prefix: CYCLE/TASK[/JOB][(FLOWS)]:STATUS"
)
LOG.info(
f'Run mode: {self.config.run_mode()}',
extra=RotatingLogFileHandler.header_extra
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/flow-triggers/13-noflow-nomerge.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ run_ok "${TEST_NAME_BASE}-run" cylc play "${WORKFLOW_NAME}"
poll_grep_workflow_log "Workflow stalled"

run_ok "${TEST_NAME_BASE}-trigger" cylc trigger --flow=none "${WORKFLOW_NAME}//1/a"
poll_grep_workflow_log -E "1/a/02\(none\):running.*=> succeeded"
poll_grep_workflow_log -E "1/a/02\(flows=none\):running.*=> succeeded"

cylc stop --now --now --max-polls=5 --interval=2 "$WORKFLOW_NAME"

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/restart/50-two-flows/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if ((CYLC_TASK_FLOW_NUMBERS == 1)); then
cylc trigger --flow=new --meta="cheese wizard" \
"$CYLC_WORKFLOW_ID//1/a"
cylc__job__poll_grep_workflow_log -E "\[1/a/02\(2\):submitted\] => running"
cylc__job__poll_grep_workflow_log -E "\[1/a/02\(flows=2\):submitted\] => running"
cylc stop $CYLC_WORKFLOW_ID
fi
"""
16 changes: 8 additions & 8 deletions tests/unit/test_flow_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@


FAKE_NOW = datetime.datetime(2020, 12, 25, 17, 5, 55)
FAKE_NOW_ISO = FAKE_NOW.isoformat()


@pytest.fixture
def patch_datetime_now(monkeypatch):

class mydatetime:
@classmethod
def now(cls):
def now(cls, tz=None):
return FAKE_NOW

monkeypatch.setattr(datetime, 'datetime', mydatetime)
Expand All @@ -49,41 +50,40 @@ def test_all(
flow_mgr = FlowMgr(db_mgr)
caplog.set_level(logging.INFO, CYLC_LOG)

# automatic: expect flow number 1
meta = "the quick brown fox"
assert flow_mgr.get_flow_num(None, meta) == 1
msg1 = f"flow: 1 ({meta}) {FAKE_NOW}"
msg1 = f"flow: 1 ({meta}) {FAKE_NOW_ISO}"
assert f"New {msg1}" in caplog.messages

# automatic: expect 2
meta = "jumped over the lazy dog"
assert flow_mgr.get_flow_num(None, meta) == 2
msg2 = f"flow: 2 ({meta}) {FAKE_NOW}"
msg2 = f"flow: 2 ({meta}) {FAKE_NOW_ISO}"
assert f"New {msg2}" in caplog.messages

# give flow 2: not a new flow
meta = "jumped over the moon"
assert flow_mgr.get_flow_num(2, meta) == 2
msg3 = f"flow: 2 ({meta}) {FAKE_NOW}"
msg3 = f"flow: 2 ({meta}) {FAKE_NOW_ISO}"
assert f"New {msg3}" not in caplog.messages
assert f"Ignoring flow metadata \"{meta}\": 2 is not a new flow" in caplog.messages

# give flow 4: new flow
meta = "jumped over the cheese"
assert flow_mgr.get_flow_num(4, meta) == 4
msg4 = f"flow: 4 ({meta}) {FAKE_NOW}"
msg4 = f"flow: 4 ({meta}) {FAKE_NOW_ISO}"
assert f"New {msg4}" in caplog.messages

# automatic: expect 3
meta = "jumped over the log"
assert flow_mgr.get_flow_num(None, meta) == 3
msg5 = f"flow: 3 ({meta}) {FAKE_NOW}"
msg5 = f"flow: 3 ({meta}) {FAKE_NOW_ISO}"
assert f"New {msg5}" in caplog.messages

# automatic: expect 5 (skip over 4)
meta = "crawled under the log"
assert flow_mgr.get_flow_num(None, meta) == 5
msg6 = f"flow: 5 ({meta}) {FAKE_NOW}"
msg6 = f"flow: 5 ({meta}) {FAKE_NOW_ISO}"
assert f"New {msg6}" in caplog.messages
flow_mgr._log()
assert (
Expand Down

0 comments on commit a454a06

Please sign in to comment.