I am not sure of the best way to create a push notification from a background service on my server to notify the client. This background service (run from within a flask_script) runs between 08:00 and 16:30 Monday to Friday. This service polls an API and does some machine learning to predict future stock values. At the moment, I am slightly confused as to how I would notify the running app that this process has completed and that a socket needs to emit a message to the client. I have the current implementation of my repository under flask_react_app on the branch flask_socketio_sql_alchemy_intergration.
Emitting events from an external process is covered in the documentation: https://flask-socketio.readthedocs.io/en/latest/#emitting-from-an-external-process.
If you want an actual example, my Flack example emits from a Celery worker. The same idea can be applied to other types of processes.
Thanks for the reply. I will look into the way your Flack example uses the Celery worker. Hopefully I should be able to apply this idea to my own process. 馃憤
I have implemented a celery background task which emits, however, my client side appear to not receive any sort of update.
Here is what I currently have. I believe the problem is within the flask_react_app where I instantiate the application and specify the message queue.
I am using gunicorn with eventlet to serve the app as seen in the Procfile.
Are you running a message queue?
Thanks for your quick reply! I believe so. I am running the redis-server. If that's what you mean by message queue?
What I mean is that I don't see anywhere in your code that you have configured the queue. Did you see the docs on how to run an external process emitter?
I'll have another look. Thanks for your help btw.
Isn't this line socketio = SocketIO(message_queue=os.environ["CELERY_BROKER_URL"]) setting the message queue? Within the flask_react_app init?
I suggest you look at the docs, plus the Flack application I referenced earlier. You need to configure the message queue on the server and the external process.
Okay. I'll keep at it. If I run into anymore problems I'll post within this issue. Again, thanks for the help.
I think I'm getting there. I have recently committed some new changes which are more inline with the way the flack application operates. I have attached the message queue in both external process and the server (I think). I am now getting an error within the celery worker as follows:
ImportError: import_string() failed for 'config.DevelopmentConfig'. Possible reasons are:
- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;
Debugged import:
- 'config' not found.
Original exception:
ImportStringError: import_string() failed for 'config'. Possible reasons are:
- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;
That seems unrelated to the change that you made. Sounds like an import for config is failing. Not sure how I can help with this, you have to locate the import and figure out why it is incorrect.
Thanks for all your help! I have now been able to emit through an external process!
Most helpful comment
Thanks for all your help! I have now been able to emit through an external process!