我有一个配芹菜的烧瓶应用程序。
当我运行该员工时,如下所示:
celery -A app.celery worker我得到以下输出
-------------- celery@local-pc v3.1.22 (Cipater)
---- **** -----
--- * *** * -- Windows-7-6.1.7601-SP1
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: app:0x483e668
- ** ---------- .> transport: mongodb://localhost:27017/app
- ** ---------- .> results: mongodb://localhost:27017/app
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> celery exchange=celery(direct) key=celery
[2016-03-08 15:52:05,587: WARNING/MainProcess] celery@local-pc ready.
[2016-03-08 15:52:08,855: ERROR/MainProcess] Process 'Worker-8' pid:9720 exited with 'exitcode 1'
[2016-03-08 15:52:08,855: ERROR/MainProcess] Process 'Worker-7' pid:11940 exited with 'exitcode 1'
[2016-03-08 15:52:08,856: ERROR/MainProcess] Process 'Worker-6' pid:13120 exited with 'exitcode 1'
...它无休止地运行,CPU提高到100%。
有关的配置是:
CELERY_BROKER_URL = 'mongodb://localhost:27017/app'
CELERY_RESULT_BACKEND = 'mongodb://localhost:27017/'
CELERY_MONGODB_BACKEND_SETTINGS = {
'database': 'app',
'taskmeta_collection': 'my_taskmeta_collection',
}
CELERY_IMPORTS = ('app.tasks', )
CELERYD_FORCE_EXEC = True
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'我的项目结构是:
proj/
config.py
app/
__init__.py
tasks.py
views.py这就是我如何在___init___.py中配置芹菜的方法“:
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
celery = make_celery(app)这就是我在tasks.py上的文章
from app import celery
@celery.task()
def add_together(a, b):
return a + b更新
当我从配置文件中删除以下行时,工作人员不会退出
CELERY_IMPORTS = ('app.tasks', )但是我得到了以下错误
Traceback (most recent call last):
File "d:\python34\lib\site-packages\celery\worker\consumer.py", line 456, in on_task_received
strategies[name](message, body,
KeyError: 'app.tasks.add_together'发布于 2017-02-23 14:44:04
在官方芹菜网站http://docs.celeryproject.org/en/3.1/getting-started/brokers/mongodb.html上
声明当您使用mongoDB作为代理时,您将承担自己的风险。
使用MongoDB 实验状态 MongoDB传输在许多方面都需要改进,并且有几个开放的bug。不幸的是,我们没有改善情况所需的资源或资金,因此我们正在寻找愿意提供帮助的捐助者和合作伙伴。
要测试是否这不是导致问题的原因,请尝试使用redis或rabbitMQ作为代理。
https://stackoverflow.com/questions/35869931
复制相似问题