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

Make --stopcp=reload use [scheduling]stop after cycle point instead of the final cycle point #4543

Merged
merged 7 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 18 additions & 20 deletions cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class Scheduler:
ext_trigger_queue: Queue

# configuration
config: WorkflowConfig # flow config
options: Values
cylc_config: DictTree # [scheduler] config

Expand All @@ -195,7 +196,6 @@ class Scheduler:
bad_hosts: Optional[Set[str]] = None

# configuration
config: Optional[WorkflowConfig] = None # flow config
flow_file: Optional[str] = None
flow_file_update_time: Optional[float] = None

Expand Down Expand Up @@ -480,7 +480,7 @@ async def configure(self):
else:
self._load_pool_from_point()

self.process_cylc_stop_point()
self.process_stop_cycle_point()
self.profiler.log_memory("scheduler.py: after load_tasks")

self.workflow_db_mgr.put_workflow_params(self)
Expand Down Expand Up @@ -1929,29 +1929,27 @@ def _check_startup_opts(self) -> None:
f"option --{opt}=reload is only valid for restart"
)

def process_cylc_stop_point(self):
"""
Set stop point.
def process_stop_cycle_point(self) -> None:
"""Set stop after cycle point.

In decreasing priority, stop cycle point (``stopcp``) is set:
* From the final point for ``cylc play --stopcp=reload``.
* From the command line (``cylc play --stopcp=XYZ``).
* From the database.
* From the flow.cylc file (``[scheduling]stop after cycle point``).

However, if ``--stopcp=reload`` on the command line during restart,
the ``[scheduling]stop after cycle point`` value is used.
"""
stoppoint = None
if self.is_restart and self.options.stopcp == 'reload':
stoppoint = self.config.final_point
elif self.options.stopcp:
stoppoint = self.options.stopcp
# Tests whether pool has stopcp from database on restart.
elif (
self.pool.stop_point and
self.pool.stop_point != self.config.final_point
):
stoppoint = self.pool.stop_point
elif 'stop after cycle point' in self.config.cfg['scheduling']:
stoppoint = self.config.cfg['scheduling']['stop after cycle point']
stoppoint = self.config.cfg['scheduling'].get('stop after cycle point')
if self.options.stopcp != 'reload':
if self.options.stopcp:
stoppoint = self.options.stopcp
# Tests whether pool has stopcp from database on restart.
elif (
self.pool.stop_point and
self.pool.stop_point != self.config.final_point
):
stoppoint = self.pool.stop_point

if stoppoint is not None:
self.options.stopcp = str(stoppoint)
Expand All @@ -1970,7 +1968,7 @@ async def handle_exception(self, exc: Exception) -> NoReturn:
await self.shutdown(exc)
raise exc from None

def validate_finalcp(self):
def validate_finalcp(self) -> None:
"""Warn if Stop Cycle point is on or after the final cycle point
"""
if self.config.final_point is None:
Expand Down
38 changes: 2 additions & 36 deletions tests/functional/cylc-play/06-warnif-scp-after-fcp.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

. "$(dirname "$0")/test_header"

set_test_number 14

# integer cycling
set_test_number 7

init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__'
[scheduler]
Expand All @@ -31,7 +29,7 @@ init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__'
initial cycle point = 1
final cycle point = 2
cycling mode = integer
[[dependencies]]
[[graph]]
P1 = foo
__FLOW_CONFIG__

Expand All @@ -53,35 +51,3 @@ for SCP in 1 2 3; do
done

purge

# Gregorian Cycling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check this for different cycling types; it should be the responsibility of the tests/unit/cycling and tests/functional/cyclers tests to ensure cycle point comparison works


init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__'
[scheduler]
allow implicit tasks = True
[scheduling]
initial cycle point = 1348
final cycle point = 1349
[[dependencies]]
P1Y = foo
__FLOW_CONFIG__

TEST_NAME="${TEST_NAME_BASE}-validate"
run_ok "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}"


for SCP in 1348 1349 1350; do
TEST_NAME="${TEST_NAME_BASE}-play-gregorian-scp=${SCP}"
workflow_run_ok "${TEST_NAME}" cylc play "${WORKFLOW_NAME}" \
--no-detach --stopcp="${SCP}"

if [[ "${SCP}" -lt 1350 ]]; then
grep_ok "Stop cycle point '.*'.*after.*final cycle point '.*'" \
"${RUN_DIR}/${WORKFLOW_NAME}/log/workflow/log" "-v"
else
grep_ok "Stop cycle point '.*'.*after.*final cycle point '.*'" \
"${RUN_DIR}/${WORKFLOW_NAME}/log/workflow/log"
fi
done

purge
56 changes: 31 additions & 25 deletions tests/functional/restart/08-stop-after-cycle-point.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ dumpdbtables() {
'SELECT cycle, name, status FROM task_pool ORDER BY cycle, name;' > taskpool.out
}

set_test_number 13
set_test_number 17
install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}"

# Check that the config stop point gets stored in DB
workflow_run_ok "${TEST_NAME_BASE}-1-run-no-cli-opts" \
workflow_run_ok "${TEST_NAME_BASE}-run" \
cylc play --no-detach "${WORKFLOW_NAME}" \
-s 'MANUAL_SHUTDOWN="1970"'
dumpdbtables
Expand All @@ -43,41 +43,47 @@ cmp_ok taskpool.out << '__OUT__'
1971|hello|waiting
__OUT__

# Check that the config stop point works (even after restart)
workflow_run_ok "${TEST_NAME_BASE}-1-restart" \
# Check that --stopcp=reload takes value from flow.cylc on restart
workflow_run_ok "${TEST_NAME_BASE}-restart-cli-stopcp-reload" \
cylc play --no-detach --stopcp=reload "${WORKFLOW_NAME}" \
-s 'MANUAL_SHUTDOWN="1971"' -s 'STOPCP="1973"'
dumpdbtables
cmp_ok stopcp.out <<< '1973'
cmp_ok taskpool.out << '__OUT__'
1972|hello|waiting
__OUT__

# Check that the stop point stored in DB works on restart
workflow_run_ok "${TEST_NAME_BASE}-restart-db-stopcp" \
cylc play --no-detach "${WORKFLOW_NAME}"
dumpdbtables
# Task hello.1973 (after stop point) should be spawned but not submitted
# Stop point should be removed from DB once reached
cmp_ok stopcp.out < /dev/null
# Task hello.1974 (after stop point) should be spawned but not submitted
cmp_ok taskpool.out <<'__OUT__'
1973|hello|waiting
1974|hello|waiting
__OUT__

delete_db

# Check that the command line stop point gets stored in DB.
workflow_run_ok "${TEST_NAME_BASE}-2-run-cli-stop" \
cylc play --no-detach --stopcp=1971 "${WORKFLOW_NAME}" \
-s 'MANUAL_SHUTDOWN="1970"'
workflow_run_ok "${TEST_NAME_BASE}-restart-cli-stopcp" \
cylc play --no-detach --stopcp=1975 "${WORKFLOW_NAME}" \
-s 'MANUAL_SHUTDOWN="1974"'
dumpdbtables
cmp_ok stopcp.out <<< '1971'
cmp_ok stopcp.out <<< '1975'
# Note we have manually stopped before the stop point
cmp_ok taskpool.out << '__OUT__'
1971|hello|waiting
1975|hello|waiting
__OUT__
# Check that the command line stop point works (even after restart)...
workflow_run_ok "${TEST_NAME_BASE}-2-restart" \
cylc play --no-detach "${WORKFLOW_NAME}"

# Check that workflow stops immediately if restarted past stopcp
workflow_run_ok "${TEST_NAME_BASE}-restart-final" \
cylc play --no-detach --stopcp=reload "${WORKFLOW_NAME}"
# Note the config value remains as 1973 (not 1972) because Jinja2 variables persist over restart
grep_workflow_log_ok "${TEST_NAME_BASE}-log-grep" "Setting stop cycle point: 1973"
dumpdbtables
cmp_ok stopcp.out < /dev/null
cmp_ok taskpool.out << '__OUT__'
1972|hello|waiting
1975|hello|waiting
__OUT__

# ... unless we reload stop point - takes value from final cycle point
# Note: we might want to rethink that - https://github.com/cylc/cylc-flow/issues/4062
workflow_run_ok "${TEST_NAME_BASE}-2-restart-cli-reload" \
cylc play --no-detach --stopcp=reload "${WORKFLOW_NAME}" \
-s 'MANUAL_SHUTDOWN="1973"'
dumpdbtables
cmp_ok stopcp.out <<< '1974'

purge
4 changes: 2 additions & 2 deletions tests/functional/restart/08-stop-after-cycle-point/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ description = """
[scheduling]
runahead limit = P1
initial cycle point = 1970
final cycle point = 1974
stop after cycle point = 1972
final cycle point = 1976
stop after cycle point = {{ STOPCP if STOPCP is defined else 1972 }}
[[graph]]
P1Y = hello

Expand Down
117 changes: 0 additions & 117 deletions tests/functional/restart/44-stop-point.t

This file was deleted.

Loading