mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] Safe API closing handling attempt
This commit is contained in:
parent
0d0c655d7f
commit
3afec9a63a
6
app.py
6
app.py
@ -7,6 +7,7 @@ from flask_cors import CORS
|
||||
|
||||
import firebase_manager
|
||||
import generic_executor
|
||||
import atexit
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app, origins="*")
|
||||
@ -116,7 +117,12 @@ def dynamic_route_handler(path):
|
||||
return generic_response_maker(http.HTTPStatus.BAD_REQUEST, str(e))
|
||||
|
||||
|
||||
def exit_safety() -> None:
|
||||
firebase_manager.set_servers_not_running()
|
||||
return
|
||||
|
||||
app.register_blueprint(apiBP)
|
||||
|
||||
if __name__ == '__main__':
|
||||
atexit.register(exit_safety)
|
||||
app.run(host='0.0.0.0', port=3000, debug=False)
|
||||
|
@ -154,6 +154,22 @@ def update_server_property(user_id: str, server_name: str, prop: str, value: str
|
||||
server_ref.update({prop: value})
|
||||
|
||||
|
||||
def set_servers_not_running():
|
||||
users_ref = firestore_database.collection(u'users')
|
||||
docs = users_ref.stream()
|
||||
|
||||
for doc in docs:
|
||||
user_id = doc.id
|
||||
servers_ref = firestore_database.collection(u'users').document(user_id).collection(u'servers')
|
||||
server_docs = servers_ref.stream()
|
||||
|
||||
for server_doc in server_docs:
|
||||
server_id = server_doc.id
|
||||
firestore_database.collection(u'users').document(user_id).collection(u'servers').document(server_id).update({u'running': False})
|
||||
|
||||
print("All servers have been set to not running.")
|
||||
|
||||
|
||||
def log_exception_to_firestore(exception: Exception = None, user_id: str = None, data: dict = None):
|
||||
new_id: str = datetime.now().strftime('%Y-%m-%d %H:%M:%S %Z%z')
|
||||
log_entry = {
|
||||
|
Loading…
Reference in New Issue
Block a user