node-celery 任务总是返回 null

问题描述

我有一个使用 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 (将#修改为@)