javascript - node-celery 任务总是返回 null
问题描述
我有一个使用 node-celery 的 JavaScript 程序,这是一个调用 celery 任务并获取结果的模块。我试图通过从“添加”芹菜任务中获得结果来开始简单。我正在遵循文档中的确切演示代码,但仍然没有返回任何结果(请参阅此链接上的文档: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);
总是返回 null,这意味着我的 JS 永远不会得到 celery 的响应。
这确实是一种奇怪的行为,表明我正在遵循文档中的确切示例,并且我还通过不仅console.log(client.ready);
在我的代码中使用而且我还尝试将CELERY_BROKER_URL
and更改为CELERY_RESULT_BACKEND
导致连接失败的不同值来验证它是否正确连接 celery 服务器. 我还将超时时间设置为最大值,它仍然返回 null 所以这不是超时问题。
这里可能是什么问题?任何帮助将不胜感激!
解决方案
推荐阅读
- ios - iOS - 进入地理围栏后获取精确的 GPS 位置
- r - R foreach() - 使用 itertools 块时如何为多个输出定义组合函数?
- r - R指定一个月中的哪一周
- java - Aspose DataSet.readXml 产生更复杂的结构
- javascript - 怎么没有弹出提示?我需要帮助设置变量以从提示输入
- dart - Flutter:如何使用 JSON 数据创建数组
- python - 获取数据帧的相同随机事件
- java - 不了解外部存储
- sql-server - SQL Server:如何以编程方式检索性能指标;特别是逻辑读取
- html - 将 Mat-Raised-Button HTML 链接制作为 PDF (Angular 6 + Material)