celerybeat-mongo icon indicating copy to clipboard operation
celerybeat-mongo copied to clipboard

Issue with Timezone

Open Jean-PhilippeD opened this issue 5 years ago • 1 comments

Hello,

I opened an issue on celery repo (https://github.com/celery/celery/issues/6617)

The last_run_at is saved in UTC in mongo but each time celery pick the task, it schedule it in UTC while I defined not to use UTC.

Jean-PhilippeD avatar Jan 26 '21 09:01 Jean-PhilippeD

I manage to get it working (dirty way) by adding a tz replacement when query the MongoScheduleEntry:

import pytz
....
Line 43:
if not self._task.last_run_at:
            self._task.last_run_at = self._default_now()
        else:
            
            europe = pytz.timezone('Europe/Paris')
            if not self._task.last_run_at.tzinfo == self._default_now().tzinfo:
                self._task.last_run_at = self._task.last_run_at.replace(tzinfo=pytz.UTC).astimezone(tz=europe)
        self.last_run_at = self._task.last_run_at

It's clearly not the best way as I put my timezone in the code but for now it does the job ;)

Jean-PhilippeD avatar Jan 26 '21 10:01 Jean-PhilippeD