Yakova commited on
Commit
5dca124
1 Parent(s): 86feaea

Update App/app.py

Browse files
Files changed (1) hide show
  1. App/app.py +10 -16
App/app.py CHANGED
@@ -1,5 +1,4 @@
1
  from fastapi import FastAPI, BackgroundTasks
2
- from contextlib import asynccontextmanager
3
  from .Editor.editorRoutes import videditor_router
4
  from App import bot
5
  from App.utilis import WorkerClient, SERVER_STATE
@@ -10,20 +9,23 @@ from .Generate.generatorRoutes import (
10
  )
11
  import uuid
12
 
 
 
 
13
 
14
- @asynccontextmanager
15
- async def lifespan(app: FastAPI):
 
16
  app.state.db = database
17
  app.state.models = models
18
-
19
  try:
20
- print("creating tables")
21
  # print(type(database.url), database_url)
22
  await models.create_all()
 
23
  await models._create_all(str(database.url))
24
- print("created")
25
- except Exception as e:
26
- print("failed to create",e)
27
  finally:
28
  print(database.is_connected)
29
  if not database.is_connected:
@@ -36,14 +38,6 @@ async def lifespan(app: FastAPI):
36
  # response = await manager.register_worker()
37
  # if not response:
38
  # print("Error registering worker")
39
- yeild
40
-
41
-
42
- app = FastAPI(lifespan=lifespan)
43
- manager = WorkerClient()
44
-
45
-
46
-
47
 
48
 
49
  @app.get("/")
 
1
  from fastapi import FastAPI, BackgroundTasks
 
2
  from .Editor.editorRoutes import videditor_router
3
  from App import bot
4
  from App.utilis import WorkerClient, SERVER_STATE
 
9
  )
10
  import uuid
11
 
12
+ app = FastAPI()
13
+ manager = WorkerClient()
14
+
15
 
16
+ @app.on_event("startup")
17
+ async def startup_event():
18
+ print("StartUp running")
19
  app.state.db = database
20
  app.state.models = models
21
+
22
  try:
 
23
  # print(type(database.url), database_url)
24
  await models.create_all()
25
+ print("Error registering worker")
26
  await models._create_all(str(database.url))
27
+ except:
28
+ print("failed to create")
 
29
  finally:
30
  print(database.is_connected)
31
  if not database.is_connected:
 
38
  # response = await manager.register_worker()
39
  # if not response:
40
  # print("Error registering worker")
 
 
 
 
 
 
 
 
41
 
42
 
43
  @app.get("/")