fix: cannot start when not ready

This commit is contained in:
estrella
2023-05-28 10:38:20 +08:00
parent 275cf26831
commit a8be3f1173
3 changed files with 9 additions and 5 deletions

View File

@@ -45,8 +45,7 @@ async def start(current_user=Depends(get_current_user)):
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
try:
program.start()
return {"status": "ok"}
return program.start()
except Exception as e:
logger.debug(e)
logger.warning("Failed to start program")
@@ -59,8 +58,7 @@ async def stop(current_user=Depends(get_current_user)):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
program.stop()
return {"status": "ok"}
return program.stop()
@router.get("/api/v1/status", tags=["program"])

View File

@@ -35,6 +35,8 @@ class Program(RenameThread, RSSThread):
self.start()
def start(self):
if self.first_run:
return {"status": "Not ready to start."}
self.stop_event.clear()
settings.load()
if self.enable_renamer:
@@ -49,6 +51,7 @@ class Program(RenameThread, RSSThread):
self.stop_event.set()
self.rename_stop()
self.rss_stop()
return {"status": "Program stopped."}
else:
return {"status": "Program is not running."}

View File

@@ -16,7 +16,10 @@ class ProgramStatus(Checker):
@property
def is_running(self):
return not self.stop_event.is_set()
if self.stop_event.is_set() or self.check_first_run():
return False
else:
return True
@property
def is_stopped(self):