[英]Using djcelery to scrape a website and populate django models
我在讓芹菜和django合作時遇到麻煩。 我想用芹菜刮擦網站並每20分鍾更新一些Django模型。
我在應用程序目錄中創建了一個具有更新類的任務文件:
class Update(PeriodicTask):
run_every=datetime.timedelta(minutes=20)
def run(self, **kwargs):
#update models
如果我從命令行運行它,該類將正確更新我的modesl:
if __name__ == '__main__':
Update().run()
我在setting.py中的芹菜配置看起來像這樣:
CELERY_RESULT_BACKEND = "database"
BROKER_HOST = 'localhost'
BROKER_PORT = 5672
BROKER_USER = 'Broker'
BROKER_PASSWORD = '*password*'
BROKER_VHOST = 'broker_vhost'
但是,當我運行manage.py celeryd -v 2
出現連接錯誤:
[2010-12-29 09:28:15,150: ERROR/MainProcess] CarrotListener: Connection Error: [Errno 111] Connection refused. Trying again in 10 seconds...
我想念什么?
更新:
我發現django-kombu看起來不錯,因為它使用了我現有的數據庫。 我已經安裝了django-kombu和kombu,但是現在在運行manage.py celeryd -v 2
時出現以下錯誤。
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "<webapp_path>/lib/python2.6/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "<webapp_path>/lib/python2.6/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "<webapp_path>/lib/python2.6/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "<webapp_path>/lib/python2.6/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "<webapp_path>/lib/python2.6/django_celery-2.1.4-py2.6.egg/djcelery/management/commands/celeryd.py", line 20, in handle
worker.run(*args, **options)
File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/bin/celeryd.py", line 83, in run
from celery.apps.worker import Worker
File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/apps/worker.py", line 15, in <module>
from celery.task import discard_all
File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/task/__init__.py", line 7, in <module>
from celery.execute import apply_async
File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/execute/__init__.py", line 7, in <module>
from celery.result import AsyncResult, EagerResult
File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/result.py", line 9, in <module>
from celery.backends import default_backend
File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/backends/__init__.py", line 51, in <module>
default_backend = DefaultBackend()
TypeError: __init__() takes exactly 2 arguments (1 given)
好像沒有安裝/運行代理(RabbitMQ?)
我遇到了同樣的問題,問題是導入路徑錯誤。
可能您將任務導入為
from celery import task
。
當你應該
from celery.task import task
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.