Heroku上的芹菜时间/日期错误?

时间:2012-08-24 18:39:23

标签: python django heroku celery

我想使用Celery在Heroku上的Django应用程序上运行一个简单的计划周期性任务。它在本地运行,我可以通过以下方式观察运行的任务:

python manage.py celerybeat

但是,当我推送到heroku并运行时:

heroku run pythonm manage.py celerybeat

我明白了:

 [2012-08-24 13:31:43,185: WARNING/MainProcess] __    -    ... __   -        _
    Configuration ->
        . broker -> django://localhost//
        . loader -> djcelery.loaders.DjangoLoader
        . scheduler -> djcelery.schedulers.DatabaseScheduler

        . logfile -> [stderr]@INFO
        . maxinterval -> 5.00 minutes (300s)
    [2012-08-24 13:31:43,186: INFO/MainProcess] Celerybeat: Starting...
    [2012-08-24 13:31:43,325: CRITICAL/MainProcess] 
celerybeat raised exception <type 'exceptions.TypeError'>: 
TypeError("can't compare offset-naive and offset-aware datetimes",)

Snippet settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'gunicorn',
    'items',
    'djcelery', 
    'kombu.transport.django'
)


import djcelery
import djcelery.schedulers
djcelery.setup_loader()
BROKER_URL = "django://"
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'America/New_York'
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"

TIME_ZONE = 'America/New_York'

Snippet tasks.py

from celery.task import PeriodicTask
from celery.registry import tasks
from datetime import timedelta
from datetime import datetime
import sys
from subprocess import Popen, PIPE
from celery.task import task, periodic_task
from celery.schedules import crontab
import time, datetime

@periodic_task(run_every=crontab(hour="*", minute="*", day_of_week="*"))
def test_task():
    print "TASK RUNNING"

Snippet requirements.txt

celery==2.5.5
django-celery==2.5.5

出了什么问题?

2 个答案:

答案 0 :(得分:1)

您应该升级到Celery 3.0.7,它修复了与时区相关的错误。

答案 1 :(得分:0)

不确定确切的解决方案,但我通过添加

解决了这个问题
USE_L10N = False
USE_TZ = False

到settings.py