change request endpoints to async

This commit is contained in:
2025-05-27 13:28:08 +02:00
parent bcc9c71c30
commit 61721a7eb6
2 changed files with 7 additions and 6 deletions
+1
View File
@@ -1,3 +1,4 @@
asgiref==3.8.1
blinker==1.9.0 blinker==1.9.0
click==8.1.8 click==8.1.8
Flask==3.1.0 Flask==3.1.0
+6 -6
View File
@@ -28,35 +28,35 @@ class Server:
self.app = Flask("Battlesnake") self.app = Flask("Battlesnake")
@self.app.get("/") @self.app.get("/")
def on_info(): async def on_info():
return self._info() return self._info()
@self.app.post("/start") @self.app.post("/start")
def on_start(): async def on_start():
game_state = request.get_json() game_state = request.get_json()
self._start(game_state) self._start(game_state)
return "ok" return "ok"
@self.app.post("/move") @self.app.post("/move")
def on_move(): async def on_move():
game_state = request.get_json() game_state = request.get_json()
return self._move(game_state) return self._move(game_state)
@self.app.post("/end") @self.app.post("/end")
def on_end(): async def on_end():
game_state = request.get_json() game_state = request.get_json()
self._end(game_state) self._end(game_state)
return "ok" return "ok"
@self.app.after_request @self.app.after_request
def identify_server(response): async def identify_server(response):
response.headers.set( response.headers.set(
"server", "battlesnake/github/starter-snake-python" "server", "battlesnake/github/starter-snake-python"
) )
return response return response
@self.app.get("/cleanup") @self.app.get("/cleanup")
def cleanup(): async def cleanup():
results = self._cleanup_database() results = self._cleanup_database()
return jsonify(data=json.loads(results), status=200) return jsonify(data=json.loads(results), status=200)