emit() messages not reaching browser when sent from APScheduler background job #1831
Replies: 3 comments 2 replies
-
Is this running in the same or different process? You can't emit from a separate process in this way. The documentation explains how to emit from a process that is not the server. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply. The case I outlined is all running from a single process. |
Beta Was this translation helpful? Give feedback.
-
It looks like the issue was due to my running the app as a single process using the Flask built-in server. With this configuration the emit() calls from the foreground did make it to the browser, but for some reason the emits() sent from the background via the APScheduler job caused the WebSocket PING command to timeout, thereby flushing my data. This code did work though when run under uwsgi. The background specific PING timeouts seem a bit odd to me but I'm happy that it all seems to work now. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Any suggestion as to why my emit() calls are not working when sent from an APScheduler background job? The emits work fine when sent from a foreground task. Stepping through the code to compare the two cases, the flow and data arguments, e.g. socket id, data & app context, appear the same and no error messages are logged but the messages don't make it to the browser. My background code is as follows:
background job invoked via APScheduler:
def cache_scheduled_show():
...
with scheduler_service.app.app_context():
if 'socketio' in flask.current_app.extensions:
logger.warn("emit track")
# stepping into this code everything looks fine but there is no message or error at the browser.
emit('newtrack', show.to_json(), namespace='/', broadcast=True)
Any pointers you could provide about this issue would be much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions