forked from Pubnic/todo-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
46 lines (35 loc) · 915 Bytes
/
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
from mangum import Mangum
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from db.services import DBService
from todos.views import todo_router
from pynamodb.exceptions import TableError
from time import sleep
app = FastAPI(
title='Todo Aplication',
)
@app.get('/')
def status():
return dict(status='OK')
app.include_router(
todo_router,
prefix='/todos',
tags=['todos']
)
@app.on_event("startup")
async def startup_event():
while(True):
try:
DBService.create_tables()
except TableError:
print('DynamoDB não está disponível ainda - Espere...')
sleep(1)
else:
break
@app.exception_handler(Exception)
async def handle_all_exceptions(request: Request, error: Exception):
return JSONResponse(
status_code=500,
content=str(error),
)
handler = Mangum(app)