@property
def crontab_pretty(self):
if self.schedule: # instance of CrontabSchedule class
# celery cron is like 'm h dw dM MY'
celery_cron_expression = str(self.schedule).split('(')[0].strip()
elements = celery_cron_expression.split(' ')
elements[2], elements[3], elements[4] = elements[4], elements[2], elements[3]
# unix cron is like 'm h dM MY dw'
unix_cron_expression = ' '.join(elements)
return cron_descriptor.get_description(unix_cron_expression)
else:
return None
We should at least match the UNIX crontab expression if we are going to use the */15 * * * * syntax -- although personally I would prefer just using the cron_descriptor.get_description function to provide a more friendly string. (Or both?)
The
CrontabSchedule.__str__
representation has two values flipped from how they appear in the conventional UNIX crontab expression format.Beat currently outputs values like
minute hour day_of_week day_of_month month_of_year
whereas UNIX convention isminute hour day_of_month month_of_year day_of_week
.https://en.wikipedia.org/wiki/Cron#CRON_expression
In my own use case using the https://github.com/Salamek/cron-descriptor library to get a friendly output like
At 04:11 AM
I had to flip the elements like so:We should at least match the UNIX crontab expression if we are going to use the
*/15 * * * *
syntax -- although personally I would prefer just using thecron_descriptor.get_description
function to provide a more friendly string. (Or both?)