feat: implement lab3 API load balancing and failover
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
--- before/src/main.py
|
||||
+++ after/src/main.py
|
||||
@@ -52 +52,4 @@
|
||||
-app.openapi = lambda: json.loads((Path(__file__).resolve().parents[1] / "contracts/openapi.json").read_text())
|
||||
+OPENAPI_SCHEMA = json.loads(
|
||||
+ (Path(__file__).resolve().parents[1] / "contracts/openapi.json").read_text()
|
||||
+)
|
||||
+app.openapi = lambda: OPENAPI_SCHEMA
|
||||
@@ -91 +94,2 @@
|
||||
- logger.error(
|
||||
+ await run_in_threadpool(
|
||||
+ logger.error,
|
||||
@@ -255 +259,2 @@
|
||||
- user = insert_user(username, display_name, hash_password(password))
|
||||
+ password_hash = await run_in_threadpool(hash_password, password)
|
||||
+ user = await run_in_threadpool(insert_user, username, display_name, password_hash)
|
||||
@@ -268 +273 @@
|
||||
-async def login(request: Request):
|
||||
+def login(request: Request):
|
||||
@@ -335 +340 @@
|
||||
- user = get_current_user(request)
|
||||
+ user = await run_in_threadpool(get_current_user, request)
|
||||
@@ -367 +372 @@
|
||||
- chat = insert_chat(user["id"], title, normalized_ids)
|
||||
+ chat = await run_in_threadpool(insert_chat, user["id"], title, normalized_ids)
|
||||
@@ -428,2 +433,2 @@
|
||||
- user = get_current_user(request)
|
||||
- chat = get_chat(chat_id, request)
|
||||
+ user = await run_in_threadpool(get_current_user, request)
|
||||
+ chat = await run_in_threadpool(get_chat, chat_id, request)
|
||||
@@ -485,2 +490,2 @@
|
||||
-def start_database_pool():
|
||||
- open_database()
|
||||
+async def start_database_pool():
|
||||
+ await run_in_threadpool(open_database)
|
||||
@@ -490,2 +495,2 @@
|
||||
-def stop_database_pool():
|
||||
- close_database()
|
||||
+async def stop_database_pool():
|
||||
+ await run_in_threadpool(close_database)
|
||||
--- before/scripts/stop-one.sh
|
||||
+++ after/scripts/stop-one.sh
|
||||
@@ -15 +15 @@
|
||||
-docker stop --time 6 "$found"
|
||||
+docker stop --timeout 6 "$found"
|
||||
--- before/scripts/rolling-update.py
|
||||
+++ after/scripts/rolling-update.py
|
||||
@@ -44 +44 @@
|
||||
- command('docker', 'stop', '--time', '6', old)
|
||||
+ command('docker', 'stop', '--timeout', '6', old)
|
||||
Reference in New Issue
Block a user