Open
Description
Can I send SSEs using an RQ worker running in a different docker container?
My code looks like this right now:
# app_factory.py
def create_app(app_name=__name__, **kwargs):
app = Flask(app_name, template_folder="./templates")
#* SSE Configuration
app.config['REDIS_URL'] = REDIS_URI_SSE
# RQ Worker function
from flask_sse import sse
def emit_markers(map_id):
sse.publish(marker_data, type="markers", channel=f"{content_id}")
sse.publish(status_data, type="status", channel=f"{content_id}")
Explanation: Any single client will be connected to a content_id
and will listen for markers
and status
, as these are both needed to populate the frontend page.
The worker will do some CPU heavy processing and generate the marker_data
and status_data
periodically on a cron schedule. The worker would need to independently send this to all the clients connected on that particular channel.
Where do I put the API endpoint? I don't really see a reason for it here? But on the client side I need to provide a value to the EventSource
declaration:
const sse = new EventSource('/api/v1/sse');
Any help will be much appreciated.
Metadata
Assignees
Labels
No labels