-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
33 lines (26 loc) · 1.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from contextlib import asynccontextmanager
import uvicorn as uvicorn
from arq import create_pool
from arq.connections import RedisSettings
from fastapi import FastAPI
from sqlmodel import SQLModel
from routing_packager_app import create_app
from routing_packager_app.constants import Providers
from routing_packager_app.db import engine, get_db
from routing_packager_app.config import SETTINGS
from routing_packager_app.api_v1.models import User
@asynccontextmanager
async def lifespan(app: FastAPI):
SQLModel.metadata.create_all(engine, checkfirst=True)
app.state.redis_pool = await create_pool(RedisSettings.from_dsn(SETTINGS.REDIS_URL))
User.add_admin_user(next(get_db()))
# create the directories
for provider in Providers:
p = SETTINGS.get_tmp_data_dir().joinpath(provider.lower())
p.mkdir(exist_ok=True)
SETTINGS.get_output_path().mkdir(exist_ok=True)
yield
app.state.redis_pool.shutdown()
app: FastAPI = create_app(lifespan=lifespan)
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=5000, reload=True)