如何解决celery 任务在 Node
我有一个使用 node-celery 的 JavaScript 程序,它是一个调用 celery 任务并获取结果的模块。我试图通过从“添加”芹菜任务中获取结果来开始简单。我正在遵循文档中的 exact 演示代码,但仍然没有返回任何结果(请参阅此链接中的文档:https://github.com/mher/node-celery(查看“后端”下的第一个示例))
芹菜代码:
@app.task(base=QueueOnce)
def add(x,y):
return x + y
JavaScript
client = celery.createClient({
CELERY_broKER_URL: "redis://myurl.com:0000/0",CELERY_RESULT_BACKEND: "redis://myurl.com:0000/0"
});
client.on('connect',function() { //on successful conncection to the celery server
console.log(client.ready); //outputs 'true' meaning my code is connecting to the celery server properly
var result = client.call('tasks.add',[1,2]); //call the 'add' task (shown above) with args as 1 and 2
setTimeout(function() {
result.get(function(data) { //when task returns result. . .
console.log(data); //output result; data will be null if the task is not finished by timeout
});
},10000); //time to time out if celery is taking too long (should not take anywhere near this long)
});
我的问题是 console.log(data);
always 返回 null,这意味着我的 JS 永远不会从 celery 得到响应。
这真的很奇怪,这表明我正在遵循文档中的确切示例,并且我还通过不仅在我的代码中使用 console.log(client.ready);
而且还尝试更改了 {{ 1}} 和 CELERY_broKER_URL
为不同的值,导致连接失败。我还将超时时间设置为最大值,但它仍然返回 null,因此这不是超时问题。
这里可能有什么问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。