Changed ProcessController to handle Server as child subprocess
This commit is contained in:
parent
9742cafad9
commit
a008bc27fa
5 changed files with 52 additions and 53 deletions
18
main.py
18
main.py
|
|
@ -4,6 +4,7 @@ from typing import Annotated
|
|||
from fastapi import FastAPI, Header
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from .classes import ProcessStatus
|
||||
from .controllers import Controllers
|
||||
from .models import Models
|
||||
from .responses import Responses
|
||||
|
|
@ -16,7 +17,7 @@ app = FastAPI()
|
|||
async def start() -> Responses.StartResponse:
|
||||
"Starts the Server process."
|
||||
|
||||
if Controllers.process.is_started():
|
||||
if Controllers.process.status() == ProcessStatus.RUNNING:
|
||||
return {"status": "running"}
|
||||
Controllers.process.start()
|
||||
return {"status": "started"}
|
||||
|
|
@ -26,9 +27,10 @@ async def start() -> Responses.StartResponse:
|
|||
async def status() -> Responses.StatusResponse:
|
||||
"Checks whether the Server is running and returns its information."
|
||||
|
||||
if not Controllers.process.is_started():
|
||||
process_status = Controllers.process.status()
|
||||
if process_status != ProcessStatus.RUNNING:
|
||||
# Crashed
|
||||
if Controllers.process.is_crashed():
|
||||
if process_status == ProcessStatus.CRASHED:
|
||||
return {"status": "crashed"}
|
||||
# Maintainance
|
||||
if Controllers.maintainance.is_set():
|
||||
|
|
@ -36,18 +38,18 @@ async def status() -> Responses.StatusResponse:
|
|||
# Offline
|
||||
return {"status": "offline"}
|
||||
|
||||
status = Controllers.server.status()
|
||||
server_status = Controllers.server.status()
|
||||
|
||||
# Starting
|
||||
if not status["online"]:
|
||||
if not server_status["online"]:
|
||||
return {"status": "starting"}
|
||||
|
||||
# Online
|
||||
return {
|
||||
"status": "online",
|
||||
"motd": status.get("motd", ""),
|
||||
"icon": status.get("icon", None),
|
||||
"players": status.get(
|
||||
"motd": server_status.get("motd", ""),
|
||||
"icon": server_status.get("icon", None),
|
||||
"players": server_status.get(
|
||||
"players",
|
||||
{
|
||||
"online": 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue