Skip to content

Commit

Permalink
added endpoint for "graceful" shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyAssassin committed Nov 19, 2024
1 parent d18e6e0 commit 96572ec
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions eyetrackvr_backend/etvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .logger import get_logger
from fastapi import APIRouter
from .tracker import Tracker
import sys

logger = get_logger()

Expand Down Expand Up @@ -74,6 +75,13 @@ def restart(self) -> None:
self.stop()
self.start()

def shutdown(self) -> None:
# NOTE: in theory this should eventually stop all child processes once they receive the stop signal
# but it's not guaranteed to work, so we should probably find a better way to handle this as sys.exit(0)
# is not a good way to handle this and doesnt work in all cases but should be good enough for now...
self.stop()
sys.exit(0)

def add_routes(self) -> None:
logger.debug("Adding routes to ETVR")
# region: Image streaming endpoints
Expand Down Expand Up @@ -113,6 +121,16 @@ def add_routes(self) -> None:
Stop the ETVR backend, this will stop all trackers and the OSC sender / receiver.
""",
)
self.router.add_api_route(
name="Shutdown the ETVR backend",
path="/etvr/shutdown",
endpoint=self.shutdown,
methods=["GET"],
tags=["default"],
description="""
Shutdown the ETVR backend, this will stop all trackers and the OSC sender / receiver and exit the program.
""",
)
self.router.add_api_route(
name="Restart ETVR",
path="/etvr/restart",
Expand Down

0 comments on commit 96572ec

Please sign in to comment.