我正在做一個應用程序在FLASK,我已經將芹菜納入它。但是,如果我想讓芹菜工人也能工作,我必須通過終端運行應用程序。 (celery -A app.celery worker
)。我試圖從主run.py
文件運行它,如下所示從FLASK應用程序運行芹菜工人
init.py
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.mail import Mail
from celery import Celery
from kombu import serialization
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
mail = Mail(app)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
app.config['CELERY_ACCEPT_CONTENT'] = ['json']
app.config['CELERY_TASK_SERIALIZER'] = 'json'
app.config['CELERY_RESULT_SERIALIZER'] = 'json'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
serialization.registry._decoders.pop("application/x-python-serialize")
from app import views
和run.py
#!flask/bin/python
from __future__ import absolute_import, unicode_literals
from app import app
# app.run(debug=True, port=9001)
from celery import current_app
from celery.bin import worker
app = current_app._get_current_object()
worker = worker.worker(app=app)
options = {
'broker': app.config['CELERY_BROKER_URL'],
'loglevel': 'INFO',
'traceback': True,
}
worker.run(**options)
但這給出了錯誤AttributeError: 'Celery' object has no attribute 'config'
任何指針,以我會做什麼錯誤將不勝感激。
芹菜整點運行它作爲一個單獨的進程,使您的Web應用程序可以卸載計算密集的任務,所以爲什麼你想運行芹菜工人在你的web應用程序相同的過程? –
基本上,命令'celery -A app.celery worker'啓動了芹菜工作人員和主應用程序。我正在尋找相當於 –