简体   繁体   中英

Correct timesettings in Django for Celery

Im wondering how to correctly use timesettings in django and celery.

Here is what I have:

TIME_ZONE = 'Europe/Oslo'
CELERY_TIMEZONE = 'Europe/Oslo'
CELERY_ENABLE_UTC = True

USE_TZ = True
TZINFO = 'UTC'

But the timestamp on my Celery task is ahead by two hours. How can I fix it?

Using:
Django - 1.6b2
celery - 3.0.23
django-celery - 3.0.23

You can use TZ default environment variable. Django will automatically use it with calling: http://docs.python.org/2/library/time.html#time.tzset If your celery runs from django, it will work there too.

Also you could use something like:

os.environ['TZ'] = 'your timezone'

at the beginning of ( manage.py or wsgi.py ) in your local installation.

I think you might be hitting a bug in django-celery that I am also running into. There were timezone related changes in the last few releases of django-celery and this bug first showed up for me when I updated from 3.0.19 to 3.0.23.

I asked about this on the #celery IRC chat and was told that the django admin based celery task view is not that great and I should be using something like Flower ( https://github.com/mher/flower ) to monitor my tasks.

I installed and ran Flower and it did not suffer from the same timestamp issues that the django-celery admin based view does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM