Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SocketIO emit from Asynchronous Celery worker is not working

I am using Flask-SocketIO to create a real-time notification system. There is an external API server that calls the socketio server in a separate thread via an RPC. The method invoked by the RPC creates a Celery task that when consumed, calls a method that invokes socketio.emit(). However, the message doesn't seem to actually be sent as no message is received in the javascript client. My instinct tells me that as the Celery worker is running in a separate process, the socketio.emit() method being called is not sending to the connected client although the objects exist at the same place in memory. The server is running gevent and Celery is receiving and completing the tasks as seen by the logs. Further I have verified that socketio.emit() is being called by the Celery worker and I have verified that when the task is called directly, bypassing Celery, socketio works as expected. Any ideas for how to get socketio to communicate correctly when it is being referenced by a celery task in a separate process?

like image 948
Mitch Skiles Avatar asked Aug 16 '14 17:08

Mitch Skiles


1 Answers

Did you forget adding the message_queue ?

socketio.init_app(app, message_queue='redis://localhost:6379/0')
like image 124
xilixjd Avatar answered Nov 15 '22 05:11

xilixjd