Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuhtz committed Jul 15, 2024
1 parent 7567d89 commit 6fcc85b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions api/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# implement REST API using FastAPI

from multiprocessing import parent_process
import psutil
import sys
import os
import signal
import logging
Expand All @@ -23,6 +21,7 @@
logger = logging.getLogger('uvicorn.error')

# from https://stackoverflow.com/questions/75975807/how-to-stop-a-loop-on-shutdown-in-fastapi

class RuntimeVals:
shutdown = False
restart = False
Expand All @@ -32,7 +31,7 @@ class RuntimeVals:

# Define API app as 'api'

api = FastAPI(lifespan=lifespan)
api = FastAPI()

def check_env_vars():
required_vars = [ 'REDIS_HOST',
Expand All @@ -43,7 +42,7 @@ def check_env_vars():
for var in required_vars:
if var not in os.environ:
logger.critical(f'env variable {var} is not set. bad image.')
api_shutdown() # bail now

logger.debug(f'env is sane.')
# we got everything, image is sane

Expand Down Expand Up @@ -74,9 +73,9 @@ async def mainloop():
# This is needed to kill the Uvicorn server and communicate the
# exit code
if runtime_cfg.restart:
print("RESTART")
logger.info('RESTART')
else:
print("SHUTDOWN")
logger.info('SHUTDOWN')
runtime_cfg.shutdown_complete = True
os.kill(os.getpid(), signal.SIGINT)

Expand Down

0 comments on commit 6fcc85b

Please sign in to comment.