-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
crons: Migrate to Cronsim library over croniter #80208
Comments
Validating DSTJust looking at the cronsim tests for DST seem very reasonable that it works correctly https://github.com/cuu508/cronsim/blob/e8bc4be781f00f0ad6d11373a11be055d7a3b4da/tests/test_cronsim.py#L293 |
Validate that the library can parse all our schedulesUsing this code from datetime import datetime, UTC
from cronsim import CronSim
valid_count = 0
invalid_expressions = []
dt = datetime(2024, 1, 1, 0, 0, tzinfo=UTC)
with open('crons.txt', "r") as file:
valid_count = 0
for line_num, expression in enumerate(file, start=1):
cron_expr = expression.strip()
try:
# Attempt to parse and simulate the cron expression
CronSim(cron_expr, dt)
valid_count += 1
except Exception as e:
# Store invalid expressions with line number and error
invalid_expressions.append((line_num, cron_expr, str(e)))
# Print results
if invalid_expressions:
for line_num, cron_expr, error in invalid_expressions:
print(error)
else:
print("No invalid expressions found.") on all existing crontab expressions in our database we get two results
The migration for the incorrect number of expressions is here I've also fixed up the whitespace while in here with
This is complete and was run in US and DE I've confirmed locally after cleaning up the schedules and fixing the warp around that the output is now
|
do we need to ensure that in addition to the library being able to parse our current crons, that the output is the same between them? |
Yep, that's why we have these two steps
|
Validate that all schedules are computed the same between croniter and cronsimTo do this I've written a script that runs against all of the cron expressions we currently have in our database. For each expression we compute the next schedule from every hour of every day in the year. import sys
from datetime import UTC, datetime, timedelta
from croniter import croniter
from cronsim import CronSim
valid_count = 0
invalid_expressions = []
start = datetime(2024, 1, 1, 0, 0, tzinfo=UTC)
bad_expressions = set()
with open("crons.txt", "r") as file:
lines = list(l for l in file)
total = len(lines)
curr = 0
for line_num, expression in enumerate(lines):
curr = curr + 1
cron_expr = expression.strip()
print(f"{curr}/{total}", end="\r")
now = start
next_year = start + timedelta(days=365)
while now < next_year:
if cron_expr in bad_expressions:
break
cronsim_next = next(CronSim(cron_expr, now))
croniter_next = croniter(cron_expr, now, ret_type=datetime).get_next()
if cronsim_next != croniter_next:
bad_expressions.add(cron_expr)
sys.stdout.write("\033[K")
print(f"bad for {cron_expr}")
print(f" from -> {now}")
print(f" croniter -> {croniter_next}")
print(f" cronsim -> {cronsim_next}")
print()
now = now + timedelta(hours=1) Here's the output. All differences as far as I can tell are due to how croniter incorrectly computes the step.
|
We're replacing croniter with cronsim as it's bit more of a modern library. This replaces the single usage outsode of the cron monitors feature of sentry. See GH-80208
We're replacing croniter with cronsim as it's bit more of a modern library. This replaces the single usage outsode of the cron monitors feature of sentry. See GH-80208
We're replacing croniter with cronsim as it's bit more of a modern library. This replaces the single usage outsode of the cron monitors feature of sentry. See GH-80208
We're replacing croniter with cronsim as it's bit more of a modern library. This replaces the single usage outsode of the cron monitors feature of sentry. See GH-80208
This is complete. |
Given problems like #66868 and the difficulty of working in the croniter codebase, we should move to cronsim.
Fixes #66868
Here's what we'll need to do to be able to move to this library
Tasks
The text was updated successfully, but these errors were encountered: