-
Notifications
You must be signed in to change notification settings - Fork 66
Add what's needed to make probes work with normal cron #482
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?
Changes from all commits
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||
| #! /usr/bin/env python3 | ||||||||||||
|
|
||||||||||||
| import argparse | ||||||||||||
| import hashlib | ||||||||||||
| import subprocess | ||||||||||||
| import time | ||||||||||||
|
|
||||||||||||
| parser = argparse.ArgumentParser( | ||||||||||||
| prog='DeterministicDelay', | ||||||||||||
| description=('Delays running a command by a consistent amount of time. ' | ||||||||||||
| 'This may be useful in spreading the load out from frequently running cronjobs.'), | ||||||||||||
| epilog=None) | ||||||||||||
|
|
||||||||||||
| parser.add_argument('-d', required=False, dest='delay', | ||||||||||||
| help=("The maximum amount of time to delay. " | ||||||||||||
| "60 seconds is the default, suffix " | ||||||||||||
| "with s (the default), m, h, or d for seconds, minutes, hours, or days.") | ||||||||||||
| ) | ||||||||||||
| parser.add_argument('commands', nargs='*', help="The commands to run") | ||||||||||||
| args = parser.parse_args() | ||||||||||||
|
|
||||||||||||
| command_hash = hashlib.sha256(bytes(str(args.commands), 'utf-8')) | ||||||||||||
| checksum = int(command_hash.hexdigest(), 16) | ||||||||||||
|
|
||||||||||||
| if not args.delay: | ||||||||||||
| max_delay = 60 | ||||||||||||
| else: | ||||||||||||
| if args.delay[-1] in ['s', 'm', 'h', 'd']: | ||||||||||||
| delay_value, delay_unit = args.delay[:-1], args.delay[-1] | ||||||||||||
| if delay_unit == 'm': | ||||||||||||
| max_delay = int(delay_value) * 60 | ||||||||||||
| elif delay_unit == 'h': | ||||||||||||
| max_delay = int(delay_value) * 60 * 60 | ||||||||||||
| elif delay_unit == 'd': | ||||||||||||
| max_delay = int(delay_value) * 24 * 60 * 60 | ||||||||||||
| else: | ||||||||||||
| max_delay = int(delay_value) | ||||||||||||
| else: | ||||||||||||
| max_delay = int(args.delay) | ||||||||||||
|
|
||||||||||||
| delay = checksum % max_delay | ||||||||||||
|
||||||||||||
| delay = checksum % max_delay | |
| if max_delay <= 0: | |
| delay = 0 | |
| else: | |
| delay = checksum % max_delay |
Copilot
AI
Feb 4, 2026
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.
When no commands are provided (empty args.commands list), subprocess.run will fail with an error. The script should validate that at least one command is provided and print a meaningful error message. Consider adding validation like if not args.commands: parser.error('No commands provided') after parsing arguments.
Copilot
AI
Feb 4, 2026
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 subprocess.run call does not check the return code or propagate the exit status of the executed command. This means that cron jobs will always appear to succeed even if the actual command fails. Consider adding sys.exit(executed.returncode) after printing the output to properly propagate the exit status.
Copilot
AI
Feb 4, 2026
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 output from subprocess.run is captured as bytes but printed directly. This will result in output like b'...' being printed instead of the actual text. The bytes should be decoded before printing, for example: print(executed.stdout.decode('utf-8')) and print(executed.stderr.decode('utf-8')). Alternatively, you can add text=True to the subprocess.run call to get string output directly.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ ADD oic.rpm /tmp | |||||||
| RUN dnf install -y epel-release.noarch && \ | ||||||||
| dnf upgrade -y && \ | ||||||||
| dnf install -y \ | ||||||||
| cronie-noanacron \ | ||||||||
| git \ | ||||||||
| gcc \ | ||||||||
| libnsl \ | ||||||||
|
|
@@ -49,5 +50,6 @@ RUN git clone https://github.com/rucio/probes.git | |||||||
| ADD rucio.config.default.cfg /tmp/ | ||||||||
|
|
||||||||
| ADD run-probes.sh / | ||||||||
| ADD DeterministicDelay / | ||||||||
|
||||||||
| ADD DeterministicDelay / | |
| ADD DeterministicDelay / | |
| RUN chmod +x /DeterministicDelay |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,14 +18,20 @@ if [ ! -z "$RUCIO_PRINT_CFG" ]; then | |||||||||||||
| echo "" | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
| cp /etc/jobber-config/dot-jobber.yaml /root/.jobber | ||||||||||||||
| if [ ! -z "$RUCIO_USING_CRON" ]; then | ||||||||||||||
| echo "Setting up and starting cron" | ||||||||||||||
| cp /etc/cron.rucio/probes-crontab /etc/cron.d/ | ||||||||||||||
|
||||||||||||||
| cp /etc/cron.rucio/probes-crontab /etc/cron.d/ | |
| if [ -f /etc/cron.rucio/probes-crontab ]; then | |
| cp /etc/cron.rucio/probes-crontab /etc/cron.d/ | |
| else | |
| echo "Warning: /etc/cron.rucio/probes-crontab not found; skipping probes cron configuration." | |
| fi |
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 delay argument parsing does not handle invalid input. If a non-numeric value is provided (e.g.,
-d abcor-d 5x), theint()conversion will raise a ValueError. Consider adding error handling with a try-except block to provide a meaningful error message instead of crashing with an unhandled exception.