Merge branch 'main' of https://git.mamahaha.work/sangge/mimajingsai into sangge-main

This commit is contained in:
dqy
2023-10-24 18:58:49 +08:00
3 changed files with 10 additions and 8 deletions

View File

@@ -35,6 +35,7 @@ def init():
def clean_env():
clear_database()
# 关闭游标和连接
cursor.close()
conn.close()
@@ -99,7 +100,7 @@ async def delete_node(ip: str) -> None:
# 接收节点心跳包
@app.post("/server/heartbeat")
@app.get("/server/heartbeat")
async def receive_heartbeat(ip: str):
cursor.execute(
"UPDATE nodes SET last_heartbeat = ? WHERE ip = ?", (time.time(), ip)
@@ -109,7 +110,7 @@ async def receive_heartbeat(ip: str):
async def receive_heartbeat_internal():
while 1:
timeout = 70
timeout = 7
# 删除超时的节点
# cursor.execute("DELETE FROM nodes WHERE last_heartbeat < ?", (time.time() - timeout,))
# conn.commit()
@@ -137,8 +138,8 @@ async def send_nodes_list(count: int) -> list:
return nodes_list
@app.get("/server/clear_database")
async def clear_database() -> None:
# @app.get("/server/clear_database")
def clear_database() -> None:
cursor.execute("DELETE FROM nodes")
conn.commit()