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

[COST-5793] remove croniter dependency #5435

Merged
merged 3 commits into from
Jan 6, 2025
Merged

[COST-5793] remove croniter dependency #5435

merged 3 commits into from
Jan 6, 2025

Conversation

maskarb
Copy link
Member

@maskarb maskarb commented Jan 6, 2025

Jira Ticket

COST-5793

Description

Remove croniter.

  • check the length of the cron string. If it is not 5 places, let's call it not valid
  • pass the string to the celery.schedule.crontab and let that do the validation. If it fails, fallback to the default.

Testing

>>> from celery.schedules import crontab
>>> from celery.schedules import ParseException
>>> def validate_cron_expression(expression, default="0 * * * *"):
...     if len(expression.split(" ", 5)) != 5:
...         print(f"Invalid cron expression: {expression}. Falling back to default {default}")
...         expression = default
...     try:
...         crontab(*expression.split(" ", 5))
...     except (ValueError, ParseException) as e:
...         print(f"Invalid cron expression: {expression}. Falling back to default {default}, Error: {e}")
...         expression = default
...     return expression
... 
>>> validate_cron_expression('hello')
Invalid cron expression: hello. Falling back to default 0 * * * *
'0 * * * *'
>>> validate_cron_expression('0 */-')
Invalid cron expression: 0 */-. Falling back to default 0 * * * *
'0 * * * *'
>>> validate_cron_expression('0 */- * * *')
Invalid cron expression: 0 */- * * *. Falling back to default 0 * * * *, Error: empty filter
'0 * * * *'
>>> validate_cron_expression('0 */ * * *')
Invalid cron expression: 0 */ * * *. Falling back to default 0 * * * *, Error: empty filter
'0 * * * *'
>>> validate_cron_expression('0 * * * *')
'0 * * * *'
>>> validate_cron_expression('0 /* * * *')
Invalid cron expression: 0 /* * * *. Falling back to default 0 * * * *, Error: Invalid weekday literal '/*'.
'0 * * * *'
>>> validate_cron_expression('0 15/ * * *')
Invalid cron expression: 0 15/ * * *. Falling back to default 0 * * * *, Error: Invalid weekday literal '15/'.
'0 * * * *'
>>> validate_cron_expression('0 15 * * *')
'0 15 * * *'
>>> 

Release Notes

  • proposed release note
* [COST-5793] remove croniter dependency

@maskarb maskarb requested review from a team as code owners January 6, 2025 15:50
@maskarb maskarb added the smoke-tests pr_check will build the image and run minimal required smokes label Jan 6, 2025
@maskarb
Copy link
Member Author

maskarb commented Jan 6, 2025

/retest

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.2%. Comparing base (cc07aa2) to head (8a919f4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #5435   +/-   ##
=====================================
  Coverage   94.2%   94.2%           
=====================================
  Files        371     371           
  Lines      31542   31542           
  Branches    3378    3378           
=====================================
+ Hits       29699   29700    +1     
+ Misses      1198    1196    -2     
- Partials     645     646    +1     

@maskarb maskarb merged commit 0df02e7 into main Jan 6, 2025
14 checks passed
@maskarb maskarb deleted the cronitor-replacement branch January 6, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smoke-tests pr_check will build the image and run minimal required smokes smokes-required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants