-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (37 loc) · 1.26 KB
/
app.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Small Fastapi app the provides a single post webhook
from fastapi import FastAPI, APIRouter, HTTPException
from pydantic_settings import BaseSettings
from contextlib import asynccontextmanager
from apscheduler.schedulers.asyncio import AsyncIOScheduler
import util
class Settings(BaseSettings):
GITHUB_REPO: str
DOWNLOAD_DIRECTORY: str
settings = Settings()
async def update():
await util.update(settings.GITHUB_REPO, settings.DOWNLOAD_DIRECTORY)
@asynccontextmanager
async def lifespan(app: FastAPI):
# Load in the initial releases
await update()
scheduler = AsyncIOScheduler()
scheduler.add_job(update, "interval", minutes=480)
scheduler.start()
yield
app = FastAPI(lifespan=lifespan, root_path="./")
@app.get("/")
async def root():
return {"message": "Hello World, check out the /docs page for more information"}
@app.get("/health")
async def health():
return {"message": "Healthy"}
@app.post("/api/hooks/release-download-toggle")
async def release_download_toggle():
try:
await update()
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
return {"message": "success"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)