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

Class method to process crontab string #8250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

padgy
Copy link

@padgy padgy commented May 14, 2023

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.

@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Patch coverage: 50.00% and project coverage change: -0.01 ⚠️

Comparison is base (1baca0c) 87.08% compared to head (59239b3) 87.07%.

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              
Flag Coverage Δ
unittests 87.04% <50.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
celery/schedules.py 96.96% <50.00%> (-0.58%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@auvipy auvipy left a 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

@stumpylog
Copy link
Contributor

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.

@auvipy
Copy link
Member

auvipy commented Jun 7, 2023

we need proper unit tests for considering that, also wait for feedback from more users

@Nusnus Nusnus self-requested a review June 16, 2023 00:29
Copy link

@jayeff jayeff left a 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(" ")
Copy link

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

Suggested change
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>

Source: https://en.wikipedia.org/wiki/Cron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants