celery / django-celery-beat

Celery Periodic Tasks backed by the Django ORM
Other
1.67k stars 428 forks source link

Crontab string representation does not match UNIX crontab expression #73

Closed pztrick closed 2 years ago

pztrick commented 7 years ago

The CrontabSchedule.__str__ representation has two values flipped from how they appear in the conventional UNIX crontab expression format.

    def __str__(self):
        return '{0} {1} {2} {3} {4} (m/h/d/dM/MY)'.format(
            cronexp(self.minute),
            cronexp(self.hour),
            cronexp(self.day_of_week),
            cronexp(self.day_of_month),
            cronexp(self.month_of_year),
        )

Beat currently outputs values like minute hour day_of_week day_of_month month_of_year whereas UNIX convention is minute 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:

    @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?)

auvipy commented 5 years ago

could you send a patch with your suggested improvement?

belongwqz commented 4 years ago

When will the version containing this fix be released?

auvipy commented 3 years ago

closing as fixed

auvipy commented 2 years ago

it was not fixed in upstream so reopened