-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
137 lines (123 loc) · 4.67 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import logging
from fastapi import FastAPI
from starlette.middleware import Middleware
from api.healthcheck import Healthcheck
from api.misc import (
FullConfigRest,
)
from api.transfer import (
Notify,
)
from config_handler import (
init_config,
)
from fast_api.routes.organization import router as org_router
from fast_api.routes.project import router as project_router
from fast_api.routes.project_setting import router as project_setting_router
from fast_api.routes.misc import router as misc_router
from fast_api.routes.comment import router as comment_router
from fast_api.routes.attribute import router as attribute_router
from fast_api.routes.embedding import router as embedding_router
from fast_api.routes.notification import router as notification_router
from fast_api.routes.data_slices import router as data_slice_router
from fast_api.routes.lookup_lists import router as lookup_lists_router
from fast_api.routes.heuristic import router as heuristic_router
from fast_api.routes.data_browser import router as data_browser_router
from fast_api.routes.labeling import router as labeling_router
from fast_api.routes.record import router as record_router
from fast_api.routes.weak_supervision import router as weak_supervision_router
from fast_api.routes.labeling_tasks import router as labeling_tasks_router
from fast_api.routes.task_execution import router as task_execution_router
from middleware.database_session import handle_db_session
from middleware.starlette_tmp_middleware import DatabaseSessionHandler
from starlette.applications import Starlette
from starlette.routing import Route, Mount
from controller.project.manager import check_in_deletion_projects
from controller.user.manager import migrate_kratos_users
from route_prefix import (
PREFIX_ORGANIZATION,
PREFIX_PROJECT,
PREFIX_PROJECT_SETTING,
PREFIX_MISC,
PREFIX_COMMENT,
PREFIX_ATTRIBUTE,
PREFIX_EMBEDDING,
PREFIX_NOTIFICATION,
PREFIX_DATA_SLICE,
PREFIX_LOOKUP_LISTS,
PREFIX_HEURISTIC,
PREFIX_DATA_BROWSER,
PREFIX_LABELING,
PREFIX_RECORD,
PREFIX_WEAK_SUPERVISION,
PREFIX_LABELING_TASKS,
PREFIX_TASK_EXECUTION,
)
from util import security, clean_up
from middleware import log_storage
from submodules.model import session
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
init_config()
migrate_kratos_users()
fastapi_app = FastAPI()
fastapi_app.include_router(
org_router, prefix=PREFIX_ORGANIZATION, tags=["organization"]
)
fastapi_app.include_router(project_router, prefix=PREFIX_PROJECT, tags=["project"])
fastapi_app.include_router(
project_setting_router, prefix=PREFIX_PROJECT_SETTING, tags=["project-setting"]
)
fastapi_app.include_router(misc_router, prefix=PREFIX_MISC, tags=["misc"])
fastapi_app.include_router(comment_router, prefix=PREFIX_COMMENT, tags=["comment"])
fastapi_app.include_router(
attribute_router, prefix=PREFIX_ATTRIBUTE, tags=["attribute"]
)
fastapi_app.include_router(
embedding_router, prefix=PREFIX_EMBEDDING, tags=["embedding"]
)
fastapi_app.include_router(
notification_router, prefix=PREFIX_NOTIFICATION, tags=["notification"]
)
fastapi_app.include_router(
data_slice_router, prefix=PREFIX_DATA_SLICE, tags=["data-slice"]
)
fastapi_app.include_router(
lookup_lists_router, prefix=PREFIX_LOOKUP_LISTS, tags=["lookup-lists"]
)
fastapi_app.include_router(
heuristic_router, prefix=PREFIX_HEURISTIC, tags=["heuristic"]
)
fastapi_app.include_router(
data_browser_router, prefix=PREFIX_DATA_BROWSER, tags=["data-browser"]
)
fastapi_app.include_router(labeling_router, prefix=PREFIX_LABELING, tags=["labeling"])
fastapi_app.include_router(record_router, prefix=PREFIX_RECORD, tags=["record"]),
fastapi_app.include_router(
weak_supervision_router, prefix=PREFIX_WEAK_SUPERVISION, tags=["weak-supervision"]
)
fastapi_app.include_router(
labeling_tasks_router, prefix=PREFIX_LABELING_TASKS, tags=["labeling-tasks"]
)
fastapi_app_internal = FastAPI()
fastapi_app_internal.include_router(
task_execution_router, prefix=PREFIX_TASK_EXECUTION, tags=["task-execution"]
)
routes = [
Route("/full_config", FullConfigRest),
Route("/notify/{path:path}", Notify),
Route("/healthcheck", Healthcheck),
Mount("/api", app=fastapi_app, name="REST API"),
Mount(
"/internal/api", app=fastapi_app_internal, name="INTERNAL REST API"
), # task master requests
]
fastapi_app.middleware("http")(handle_db_session)
middleware = [Middleware(DatabaseSessionHandler)]
app = Starlette(routes=routes, middleware=middleware)
check_in_deletion_projects()
security.check_secret_key()
clean_up.clean_up_database()
clean_up.clean_up_disk()
session.start_session_cleanup_thread()
log_storage.start_persist_thread()