How to emit(through call method) socket events from Celery tasks to clients connected via socketio.ASGIApp
#1478
-
Hello everyone I'm working with a FastAPI backend using Setup:
Goal: What I’ve already tried / read: While those approaches work for Question: Should I:
If there’s a recommended pattern or best practice for this case, I’d love to hear it — and code snippets would be very helpful too. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The limitation here is that your Celery process is not a server process, so it is not set up to listen, which is necessary to receive the callback notifications that the The intention of this feature is to provide a quick way for a non-server process to send a message to a client through the server. If you need more than that, then you will have to use a different solution. For example, your Celery job can connect to the FastAPI server as a Socket.IO client (using the |
Beta Was this translation helpful? Give feedback.
-
thank you for the reply @miguelgrinberg . |
Beta Was this translation helpful? Give feedback.
The limitation here is that your Celery process is not a server process, so it is not set up to listen, which is necessary to receive the callback notifications that the
call()
method uses. Without the ability to listen, there is no way to do this.The intention of this feature is to provide a quick way for a non-server process to send a message to a client through the server. If you need more than that, then you will have to use a different solution.
For example, your Celery job can connect to the FastAPI server as a Socket.IO client (using the
Client
orAsyncClient
classes in the python-socketio package). Then it can talk to the server directly via WebSocket, which can listen for messag…