Skip to content
Draft
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"PyGithub==1.55",
"colorama==0.4.5",
"coloredlogs==15.0.1", # NOTE(PG): Should be removed during cleanup for loguru instead
"dpath>=2.0.7", # Maximum version for Python 3.6 support
Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

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

The version specifier '>=2.0.7' contradicts the comment stating a maximum version is required for Python 3.6 support. Consider revising the version constraint (e.g., using '<=' if a maximum version is intended).

Suggested change
"dpath>=2.0.7", # Maximum version for Python 3.6 support
"dpath>=2.0.7, <2.1.0", # Maximum version for Python 3.6 support

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bad suggestion, or maybe an indication of bad working in my comment: we need 2.0.7 or newer (2.0.7 is the highest version still supports Python 3.6)

"emoji==1.7.0",
"f90nml==1.4.2",
"gfw-creator==0.2.2",
Expand Down
63 changes: 60 additions & 3 deletions src/esm_runscripts/observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import sys
import time

import dpath.util
import psutil

from loguru import logger

from . import database_actions, helpers, logfiles
Expand Down Expand Up @@ -143,12 +143,35 @@ def assemble_error_list(config):
frequency = int(frequency)
except:
frequency = 60
if (
Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

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

If only one of 'set_config_key' or 'set_config_value' is provided, the config update is silently skipped. Consider adding logging or a warning to help debug misconfigurations.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Logging would be helpful, that is a good suggestion...

Copy link

Copilot AI Apr 15, 2025

Choose a reason for hiding this comment

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

The variables 'set_config_key' and 'set_config_value' are defined conditionally. To ensure they are always available later in the function, consider initializing them to None before the conditional block.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is done below, so the comment is not needed.

"set_config_key" in config[model]["check_error"][trigger]
and "set_config_value" in config[model]["check_error"][trigger]
):
set_config_key = config[model]["check_error"][trigger][
"set_config_key"
]
set_config_value = config[model]["check_error"][trigger][
"set_config_value"
]
else:
set_config_key = None
set_config_value = None

elif isinstance(config[model]["check_error"][trigger], str):
pass
else:
continue
error_list.append(
(trigger, search_file, method, frequency, frequency, message)
(
trigger,
search_file,
method,
frequency,
frequency,
message,
set_config_key,
set_config_value,
)
)
config["general"]["error_list"] = error_list
return config
Expand All @@ -171,6 +194,8 @@ def check_for_errors(config):
next_check,
frequency,
message,
set_config_key,
set_config_value,
) in error_check_list:
warned = 0
if next_check <= time:
Expand All @@ -181,8 +206,31 @@ def check_for_errors(config):
if method == "warn":
warned = 1
monitor_file.write("WARNING: " + message + "\n")
if (
set_config_key is not None
and set_config_value is not None
):
dpath.util.set(
config,
set_config_key,
set_config_value,
separator=".",
)
logger.info(
f"Set {set_config_key}={set_config_value} in check_for_errors"
)
break
elif method == "kill":
if (
set_config_key is not None
and set_config_value is not None
):
dpath.util.set(
config,
set_config_key,
set_config_value,
separator=".",
)
cancel_job = f"scancel {config['general']['jobid']}"
monitor_file.write("ERROR: " + message + "\n")
monitor_file.write("Will kill the run now..." + "\n")
Expand All @@ -195,7 +243,16 @@ def check_for_errors(config):
next_check += frequency
if warned == 0:
new_list.append(
(trigger, search_file, method, next_check, frequency, message)
(
trigger,
search_file,
method,
next_check,
frequency,
message,
set_config_key,
set_config_value,
)
)
config["general"]["error_list"] = new_list
return config
Expand Down
Loading