Skip to content

Commit 8ce9d96

Browse files
committed
test(server): Auto update with git pull
1 parent c04beee commit 8ce9d96

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

module/server/home_router.py

+11
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,14 @@ async def update_info():
6060
except Exception as e:
6161
logger.error(e)
6262
return None
63+
64+
@home_app.get('/execute_update')
65+
async def execute_update():
66+
# 下拉仓库 -> 关闭所有脚本进程 -> 最后重启oasx
67+
try:
68+
updater = Updater()
69+
updater.execute_pull()
70+
except Exception as e:
71+
logger.error(e)
72+
return '手动更新将会立即结束运行中的脚本服务, 最后你还需重启oasx'
73+

module/server/updater.py

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def check_update(self) -> bool:
121121
logger.info(f"No update")
122122
return False
123123

124+
def execute_pull(self) -> bool:
125+
source = "origin"
126+
for _ in range(3):
127+
if self.execute(
128+
f'"{self.git}" pull {source} {self.Branch} --no-rebase', allow_failure=True
129+
):
130+
break
131+
else:
132+
logger.warning("Git fetch failed")
133+
return False
134+
135+
124136

125137
if __name__ == "__main__":
126138
updater = Updater()

script.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ def run(self, command: str) -> bool:
386386
logger.critical('This is likely to be a mistake of developers, but sometimes just random issues')
387387
self.config.notifier.push(title=command, content=f"<{self.config_name}> ScriptError")
388388
exit(1)
389-
except RequestHumanTakeover:
389+
except RequestHumanTakeover as e:
390+
logger.critical(e)
390391
logger.critical('Request human takeover')
391392
self.config.notifier.push(title=command, content=f"<{self.config_name}> RequestHumanTakeover")
392393
exit(1)

server.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def fun(ev: threading.Event):
5454
logger.attr("Port", port)
5555
logger.attr("Reload", ev is not None)
5656

57-
uvicorn.run("module.server.app:fastapi_app", host=host, port=port, factory=True)
57+
uvicorn.run("module.server.app:fastapi_app",
58+
host=host,
59+
port=port,
60+
factory=True)
5861

5962

6063

0 commit comments

Comments
 (0)