Skip to content

Commit

Permalink
chore: minor fastapi tweaks (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSehrawat authored Jun 16, 2024
1 parent adc4e9a commit cc90a1e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ async def dispatch(self, request: Request, call_next):
finally:
process_time = time.time() - start_time
logger.log(
"API", f"{request.method} {request.url.path} - {response.status_code if 'response' in locals() else '500'} - {process_time:.2f}s"
"API",
f"{request.method} {request.url.path} - {response.status_code if 'response' in locals() else '500'} - {process_time:.2f}s",
)
return response


parser = argparse.ArgumentParser()
parser.add_argument(
"--ignore_cache",
Expand All @@ -43,7 +45,16 @@ async def dispatch(self, request: Request, call_next):

args = parser.parse_args()

app = FastAPI()
app = FastAPI(
title="Riven",
summary="A media management system.",
version="0.7.x",
redoc_url=None,
license_info={
"name": "GPL-3.0",
"url": "https://www.gnu.org/licenses/gpl-3.0.en.html",
},
)
app.program = Program(args)

app.add_middleware(LoguruMiddleware)
Expand All @@ -61,6 +72,7 @@ async def dispatch(self, request: Request, call_next):
app.include_router(webhooks_router)
app.include_router(tmdb_router)


class Server(uvicorn.Server):
def install_signal_handlers(self):
pass
Expand All @@ -80,6 +92,7 @@ def run_in_thread(self):
finally:
self.should_exit = True


config = uvicorn.Config(app, host="0.0.0.0", port=8080, log_config=None)
server = Server(config=config)

Expand All @@ -96,4 +109,4 @@ def run_in_thread(self):
finally:
app.program.stop()
logger.critical("Server has been stopped")
sys.exit(0)
sys.exit(0)

0 comments on commit cc90a1e

Please sign in to comment.