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 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions celery/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@
self.month_of_year = self._expand_cronspec(month_of_year, 12, 1)
super().__init__(**kwargs)

@classmethod
def from_string(cls, crontab: str):
"""
Create a Crontab from a string. For example ``crontab='* * * * *'``.
"""
minute, hour, day_of_month, month_of_year, day_of_week = crontab.split(" ")
return cls(minute, hour, day_of_week, day_of_month, month_of_year)

Check warning on line 417 in celery/schedules.py

View check run for this annotation

Codecov / codecov/patch

celery/schedules.py#L416-L417

Added lines #L416 - L417 were not covered by tests

@staticmethod
def _expand_cronspec(
cronspec: int | str | Iterable,
Expand Down