我想让一个函数排队在后台运行(使用Redis队列),并在函数完成后向客户端发送消息,因此在后台任务完成后使用send(msg)
使用Flask SocketIO。这是密码
# Server
@app.route("/update")
def update():
job = q.enqueue(updateFiles) # Send function to background
return render_template("index.html")
@socketio.on("message")
def updateFiles(msg): # Function running on background
time.sleep(5)
send(msg) # Sending message to the client after executing functions updateFiles
# HTML (jQuery):
socket.emit("message", "Files updated successfully"); // Emitting message to server
socket.on('message', function (msg) { // Receive message from server and show it on HTML template
$("#message").html(msg);
});
在服务器(Heroku)上出现以下错误:
2021-02-22T05:12:00.810166+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/rq/job.py", line 719, in _execute
2021-02-22T05:12:00.810172+00:00 app[worker.1]: return self.func(*self.args, **self.kwargs)
2021-02-22T05:12:00.810172+00:00 app[worker.1]: TypeError: actualizarExpedientes() missing 1 required positional argument: 'msg'
我发现问题是job = q.enqueue(updateFiles)
,因为updatefile需要一个参数。问题是参数msg
在自动使用jQuery发出消息后来自SocketIO。如何解决这个问题
目前没有回答
相关问题 更多 >
编程相关推荐