Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to send SSE with RQ worker, how to configure? #31

Open
amks1 opened this issue Aug 5, 2021 · 2 comments
Open

Want to send SSE with RQ worker, how to configure? #31

amks1 opened this issue Aug 5, 2021 · 2 comments

Comments

@amks1
Copy link

amks1 commented Aug 5, 2021

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.

@emilsgulbis
Copy link

emilsgulbis commented Dec 17, 2021

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.

Did you manage to make this work?

@amks1
Copy link
Author

amks1 commented Dec 19, 2021

Not really. I've been using websockets instead...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants