我刚刚开始使用 Celery,其中 Celery 工作线程是用 Python 编写的,任务是使用 node-celery
从 Node/Meteor 发送的。
为什么client.call()
没有返回结果
? Python工作控制台显示任务已发送并成功处理。但是 ready
和 pending
事件似乎都没有触发!
使用 Celery 3.1.7、RabbitMQ 3.2.2、node-celery 0.1.1、Meteor 0.7.0.1
Node
var celery = Meteor.require('node-celery'),
client = celery.createClient({
CELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',
CELERY_RESULT_BACKEND: 'amqp://',
CELERY_TASK_SERIALIZER: 'json',
CELERY_RESULT_SERIALIZER: 'json'
});
client.on('error', function(err) {
console.log(err);
});
client.on('connect', function() {
console.log('Connected')
var results = client.call('tasks.echo', ['Hello world'], function(result) {
console.log('results:' + result);
});
results.on('pending', function(result) {
console.log('pending: ' + result)
});
results.on('ready', function(result) {
console.log(result)
});
});
输出
Connected
最佳答案
编辑:
你现在可以在atmospheric上找到我的celery package,或者直接使用mrt install celery
安装
我经历了设置此过程的痛苦,但已经走出了另一边。
我最终不得不分支 node-celery
( https://github.com/nathan-muir/node-celery ) 和 node-amqp
( https://github.com/nathan-muir/node-amqp ) 来创建可行的版本。
我已将所有这些装进 meteor 包中 - 但我还没有清理所有内容以供一般消费。 (https://github.com/nathan-muir/meteor-celery)。我想用 Fibers/Futures 包装它,而不是保留回调样式(欢迎拉取请求。
该包从Meteor.settings.celery
读取,因此创建一个设置文件,例如:
{
"celery": {
"CELERY_BROKER_URL": "amqp://guest@localhost:5672//",
"CELERY_RESULT_BACKEND": "amqp",
"CELERY_SEND_TASK_SENT_EVENT": true
}
}
并使用meteor --settings path/to/settings.json
我还运行启用了事件的客户端和工作人员 (celery worker -E --config=xx
),因此我可以使用 celery 监控工具(以及我自己的自定义 cloudwatch 统计监控 https://github.com/nathan-muir/celery-cloudwatch )
如果您还有其他问题 - 请随时在评论中提问。
关于python - 使用 node-celery(MeteorJS) 和 ampq 后端时,Celery 不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20983843/