2014-10-07 48 views
2

我嘗試配置celerydjango和使用3-tier project layout。我已經運行了syncdbmigration命令。但是當我開始工作時,我會遇到一些錯誤。有人可以幫幫我嗎?非常感謝。用django配置芹菜[獲取一些錯誤]

這裏是我的項目佈局

- 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 

編輯 - >>> 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 

然後我得到以下錯誤。

-------------- [email protected] 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 

EDIT 2 - >

我注意到一兩件事。當我運行celery -A ... command時,它會在src(This is wrong)中創建db.sqlite。當我執行syncdb命令時,在根中創建db.sqlite文件。哪個更好

+0

你能分享你的'INSTALLED_APPS'設置嗎?這可能是因爲沒有添加「kombu.transport.django」 – srj 2014-10-07 19:18:46

+0

@srj'kombu.transport.django'已添加到'kombu.transport.django'中。 – Shah 2014-10-07 19:21:34

+0

請分享INSTALLED_APPS。你如何創建sql表?通過'syncdb'? – srj 2014-10-07 19:22:56

回答

1

celery可執行文件使用SQLite數據庫root,而Django使用另一個SQLite project/settings/。使用絕對路徑修復SQLite數據庫在settings/local.py的路徑:

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