用django配置芹菜[得到一些错误]

时间:2014-10-07 18:58:14

标签: django celery django-celery

我尝试使用celery并使用django配置3-tier project layout。我已经运行了syncdbmigration命令。但是当我开始工作时,我遇到了一些错误。有人可以帮帮我吗?非常感谢。

这是我的项目布局

- root/
    - src/
        - project/
            - __init__.py <<< celery imports added
            - urls.py
            - celery.py
        - core/
            tasks.py
        - manage.py

我运行的命令

    $ cd root
    $ celery -A project --workdir=src/ worker -l info

修改 - &gt;&gt;&gt; celery.py。 这是我的INSTALLED_APP设置。

os.environ.setdefault('DJANGO_SETTINGS_MODULE',
                      'project.settings.local')

app = Celery('project', broker='django://')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

CELERYBEAT_SCHEDULE = {
    'every-hour': {
        'task': 'core.tasks.sync_currency_rates',
        'schedule': crontab(minute='*/1')
    },
}

CELERY_TIMEZONE = 'UTC'
CELERY_ALWAYS_EAGER = True

然后我收到了以下错误。

-------------- celery@Kulbirs-Mac-mini.local v3.1.16 (Cipater)
---- **** ----- 
--- * ***  * -- Darwin-13.4.0-x86_64-i386-64bit
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         actionsuite:0x10f929890
- ** ---------- .> transport:   django://localhost//
- ** ---------- .> results:     disabled
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- 
--- ***** ----- [queues]
 -------------- .> celery           exchange=celery(direct) key=celery


[tasks]
  . core.tasks.sync_currency_rates

[2014-10-07 18:52:17,662: INFO/MainProcess] Connected to django://localhost//
[2014-10-07 18:52:17,678: ERROR/MainProcess] Unrecoverable error: OperationalError('no such table: djkombu_queue',)
Traceback (most recent call last):
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/worker/__init__.py", line 206, in start
    self.blueprint.start(self)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
    step.start(parent)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/bootsteps.py", line 374, in start
    return self.obj.start()
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/worker/consumer.py", line 278, in start
    blueprint.start(self)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
    step.start(parent)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/worker/consumer.py", line 608, in start
    c.connection, on_decode_error=c.on_decode_error,
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/celery/app/amqp.py", line 375, in __init__
    **kw
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/messaging.py", line 359, in __init__
    self.revive(self.channel)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/messaging.py", line 371, in revive
    self.declare()
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/messaging.py", line 381, in declare
    queue.declare()
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/entity.py", line 505, in declare
    self.queue_declare(nowait, passive=False)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/entity.py", line 531, in queue_declare
    nowait=nowait)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/transport/virtual/__init__.py", line 446, in queue_declare
    self._new_queue(queue, **kwargs)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/kombu/transport/django/__init__.py", line 36, in _new_queue
    Queue.objects.get_or_create(name=queue)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/query.py", line 422, in get_or_create
    return self.get(**lookup), False
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/query.py", line 351, in get
    num = len(clone)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/query.py", line 122, in __len__
    self._fetch_all()
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/query.py", line 966, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 700, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
    cursor.execute(sql, params)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/sandhu/Envs/allout/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
OperationalError: no such table: djkombu_queue

编辑2 - &gt;

我还注意到了一件事。当我运行celery -A ... command时,它会在db.sqlite中创建src(This is wrong)。当我执行在{root}中创建syncdb文件的db.sqlite命令时。这很好

1 个答案:

答案 0 :(得分:1)

celery可执行文件在root使用SQLite数据库,而Django在project/settings/使用另一个SQLite。使用绝对路径修复settings/local.py中SQLite DB的路径:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(os.path.dirname(__file__), "my_database.sq3"),
    }
}