-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (39 loc) · 1.21 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# TODO: Figure out ratelimiting
# TODO: Figure out pagination
# TODO: Is there anything important that I'm overlooking wrt to sessions?
# TODO: Handle errors better lol
import asyncio
import os
import cameras
import status
import uvicorn
from fastapi import FastAPI
import db
from config import config
from routes import auth, dev, printers, jobs, users
app = FastAPI(title="Enok")
app.include_router(auth.router)
app.include_router(dev.router)
app.include_router(printers.router)
app.include_router(jobs.router)
app.include_router(users.router)
@app.get("/")
def read_root():
return {"enok": app.version}
async def periodic(loop: asyncio.AbstractEventLoop):
status.update_printer_status()
cameras.on_state_update()
cameras.loop()
await asyncio.sleep(config.printerCheckFrequency)
loop.create_task(periodic(loop))
@app.on_event("startup")
async def startup_event():
if not os.path.exists(config.files_location):
os.mkdir(config.files_location)
loop = asyncio.get_running_loop()
loop.create_task(periodic(loop))
@app.on_event("shutdown")
def shutdown_event():
db.con.close()
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=config.dev)