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

Clean other remotes after error. #4950

Closed
wants to merge 1 commit into from
Closed
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
46 changes: 30 additions & 16 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,30 +782,44 @@ def init_clean(reg: str, opts: 'Values') -> None:
# Parse --rm option to make sure it's valid
rm_dirs = parse_rm_dirs(opts.rm_dirs) if opts.rm_dirs else None

remote_clean_failed = False
err = ""
if not opts.local_only:
platform_names = None
try:
platform_names = get_platforms_from_db(local_run_dir)
except FileNotFoundError:
if opts.remote_only:
raise ServiceFileError(
f"No workflow database for {reg} - cannot perform "
"remote clean"
)
LOG.info(
f"No workflow database for {reg} - will only clean locally"
remote_clean_failed = True
err = (
f"No workflow database for {reg} - cannot perform "
"remote clean"
)
except ServiceFileError as exc:
raise ServiceFileError(f"Cannot clean {reg} - {exc}")

if platform_names and platform_names != {'localhost'}:
remote_clean(
reg, platform_names, opts.rm_dirs, opts.remote_timeout
)
remote_clean_failed = True
err = f"Cannot clean {reg} - {exc}"
else:
if platform_names and platform_names != {'localhost'}:
try:
remote_clean(
reg, platform_names, opts.rm_dirs, opts.remote_timeout
)
except (PlatformLookupError, CylcError) as exc:
remote_clean_failed = True
err = str(exc)

if not opts.remote_only:
# Must be after remote clean
clean(reg, local_run_dir, rm_dirs)
if opts.remote_only:
if remote_clean_failed:
raise CylcError(err)
else:
if remote_clean_failed:
# Deleting the db would prohibit future remote cleaning (e.g. if
# the remote host was temporarily down).
LOG.error(err)
raise CylcError(
f"Not cleaning {reg} locally because remote clean failed.")
else:
# Clean locally - must be done after remote.
clean(reg, local_run_dir, rm_dirs)


def clean(reg: str, run_dir: Path, rm_dirs: Optional[Set[str]] = None) -> None:
Expand Down