initialization as fastcgi event

This commit is contained in:
boyska 2021-08-25 00:53:38 +02:00
parent 2341849e54
commit 15376a1052
2 changed files with 8 additions and 2 deletions

View file

@ -60,6 +60,7 @@ class DateTimeAction(Action):
raise ValueError("'%s' is not a valid datetime" % values)
setattr(namespace, self.dest, parsed_val)
code_dir = os.path.dirname(os.path.realpath(__file__))
def common_pre():
prechecks = [pre_check_user, pre_check_permissions, pre_check_ffmpeg]
@ -76,7 +77,7 @@ def common_pre():
if getattr(sys, "frozen", False):
os.chdir(sys._MEIPASS)
else:
os.chdir(os.path.dirname(os.path.realpath(__file__)))
os.chdir(code_dir)
for conf in configs:
get_config().from_pyfile(conf)

View file

@ -21,7 +21,7 @@ logger = logging.getLogger("server")
common_pre()
app = FastAPI()
db = RecDB(get_config()["DB_URI"])
db = None
def date_read(s):
@ -38,6 +38,11 @@ def rec_sanitize(rec):
d["endtime"] = date_write(d["endtime"])
return d
@app.on_event("startup")
async def startup_event():
global db
common_pre()
db = RecDB(get_config()["DB_URI"])
@app.get("/date/date")
def date():