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
Class method to process crontab string #8250
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #8250 +/- ##
==========================================
- Coverage 87.08% 87.07% -0.01%
==========================================
Files 148 148
Lines 18467 18471 +4
Branches 2524 2524
==========================================
+ Hits 16082 16084 +2
- Misses 2106 2108 +2
Partials 279 279
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
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.
I would like to know more context and examples and unit tests for the proposed change
I can give at least one example where this would be useful. In paperless-ngx, the user is able to control the timing of tasks by providing a cron expression to overwrite the default scheduling. We manually process what they give us here to create a celery crontab to configure celery beat. Having a convenient method built in (and tested by) celery would be useful for us as a celrey beat user. |
we need proper unit tests for considering that, also wait for feedback from more users |
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.
I too think having a convenience method to get a crontab
from a cron expression would be helpful in cases where you use configration (e.g. enviroment variable) to define a schedule for some tasks. We use this quite a lot to have different schedules for different runtime enviroments
I would suggest to use the official cron format though as per suggestion
@auvipy In case you give a go ahead I could update the format and add some unit tests to this PR so that it can be merged
""" | ||
Create a Crontab from a string. For example ``crontab='* * * * *'``. | ||
""" | ||
minute, hour, day_of_week, day_of_month, month_of_year = crontab.split(" ") |
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.
I would suggest to switch the order of fields to match offical cron format
minute, hour, day_of_week, day_of_month, month_of_year = crontab.split(" ") | |
minute, hour, day_of_month, month_of_year, day_of_week = crontab.split(" ") |
# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of the month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of the week (0–6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>
Convenience method for creating a crontab object from a string. Many configurations in systems are written as a cron string, so adding a helper function for this would make reading schedules easier.