-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update cron monitor script #11632
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
base: master
Are you sure you want to change the base?
Update cron monitor script #11632
Changes from all commits
9bb6df2
967a2d7
9bdaa3f
ea3a22b
375ea51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,34 +6,32 @@ | |||||||||||
| import argparse | ||||||||||||
| import subprocess | ||||||||||||
| import sys | ||||||||||||
| from configparser import ConfigParser | ||||||||||||
| from pathlib import Path | ||||||||||||
|
|
||||||||||||
| import sentry_sdk | ||||||||||||
| import yaml | ||||||||||||
| from statsd import StatsClient | ||||||||||||
|
|
||||||||||||
| DEFAULT_CONFIG_PATH = "/olsystem/etc/cron-wrapper.ini" | ||||||||||||
| DEFAULT_CONFIG_PATH = "/olsystem/etc/openlibrary.yml" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class MonitoredJob: | ||||||||||||
| def __init__(self, command, sentry_cfg, statsd_cfg, job_name): | ||||||||||||
| def __init__(self, command, sentry_cfg, statsd_server, monitor_slug): | ||||||||||||
| self.command = command | ||||||||||||
| self.statsd_client = ( | ||||||||||||
| self._setup_statsd(statsd_cfg.get("host", ""), statsd_cfg.get("port", "")) | ||||||||||||
| if statsd_cfg | ||||||||||||
| else None | ||||||||||||
| statsd_host_and_port = statsd_server.split(":") | ||||||||||||
| self.statsd_client = self._setup_statsd( | ||||||||||||
| statsd_host_and_port[0], statsd_host_and_port[1] | ||||||||||||
| ) | ||||||||||||
| self._setup_sentry(sentry_cfg.get("dsn", "")) | ||||||||||||
| self.job_name = job_name | ||||||||||||
| self.monitor_slug = monitor_slug | ||||||||||||
| self.job_failed = False | ||||||||||||
|
|
||||||||||||
| def run(self): | ||||||||||||
| self._before_run() | ||||||||||||
| try: | ||||||||||||
| self._run_script() | ||||||||||||
| with sentry_sdk.monitor(self.monitor_slug): | ||||||||||||
| self._run_script() | ||||||||||||
| except subprocess.CalledProcessError as e: | ||||||||||||
| se = RuntimeError(f"Subprocess failed: {e}\n{e.stderr}") | ||||||||||||
| sentry_sdk.capture_exception(se) | ||||||||||||
| self.job_failed = True | ||||||||||||
| sys.stderr.write(e.stderr) | ||||||||||||
|
||||||||||||
| sys.stderr.write(e.stderr) | |
| if e.stderr is not None: | |
| sys.stderr.write(e.stderr) | |
| else: | |
| sys.stderr.write(str(e)) |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status label "stop" for successful job completion is unclear and inconsistent with conventional metric naming. Consider using "success" instead to make the metric's meaning more explicit and align with common monitoring conventions where job outcomes are typically labeled as "success" or "failure".
| status = "failure" if self.job_failed else "stop" | |
| status = "failure" if self.job_failed else "success" |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting config to None immediately after reading it creates potential issues if the config needs to be referenced later and makes the code confusing. This line appears to be an attempt at memory cleanup but is unnecessary in Python's garbage collection model. Consider removing this line as it reduces code clarity without providing benefits.
| config = None |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message "Missing cron-wrapper configuration file" is misleading because it doesn't indicate which file path was checked. Consider including the config_path in the error message to help users diagnose configuration issues more easily.
| raise FileNotFoundError("Missing cron-wrapper configuration file") | |
| raise FileNotFoundError(f"Missing cron-wrapper configuration file: {config_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statsd_server string is split without validation, which will cause an IndexError if the string is empty or doesn't contain a colon separator. Additionally, the port value needs to be converted to an integer for StatsClient. Add validation to ensure statsd_server is in the expected "host:port" format and convert the port to int before passing to _setup_statsd.