Closed timofurrer closed 7 years ago
I did some research on this, mongoengine has an MongoEngineConnectionError and pymongo has AutoReconnectError but that only works when a connection is lost.
Maybe we can use the MongoEngineConnectionError, but I am not sure how, any ideas?
We could also manually create a mongodb connection to check if it is running, but that would create a lot of overhead and is ugly.
Do you have any suggestions?
Well, the best way to complain to the user would be upon minion submit
(git minion
) (with some hints about how to start the mongodb server).
However, not the client but the server should detect this issue and return this to the client on ... maybe create_job()
?
We could try to open a connection - that's what you have to do to see if there's is something (or you'll parse open ports ... netstat ...
) but that's ugly as well.
So, you might be best of with trying to open a connection using mongoengine.
What do you think?
well, we could builtin a check to see if the mongodb is running, if not and the user does an minion sumbit
the response would be something like: error: no connection with database
.
netstat
could be a solution. But I think output is platform specific so that would add a lot of work. I will look into opening a connection with mongoengine or pymongo.
The connection error msg sounds good to me! Make sure that you add a hint to start the mongodb server.
Maybe you can implemented a decorator which checks the connections and use them on the route handler functions, like:
@app.route('...')
@ensure_mongo
def create_job(...):
...
I found a way to catch errors and exceptions in Flask.
With the following code:
@api.errorhandler(Exception)
def catch_all_errors(error):
print(error)
return "error", 500
I can catch all errors and filter which are related to pymongo and mongoengine. I will test some scenario's and build in checks for the mongo errors instead of a catch all.
pymongo has a good list with exceptions and errors, so this shouldn't be so hard to do.
Any ideas on this?
The python
mongoengine
just hangs if no server is started. The minion server/client should complain.