app_module.py
2.32 KB
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
"""Bootstrap helpers for assembling the web API app module."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Callable
from flask import Flask
from flask_socketio import SocketIO
from apps.web_api.bootstrap import runtime as runtime_bootstrap
from apps.web_api.bootstrap.cleanup import register_reload_safe_cleanup_handler
from apps.web_api.bootstrap.http_config import resolve_frontend_dev_server_url
from apps.web_api.bootstrap.search_hooks import SearchHookSource
from apps.web_api.factory import create_app
from apps.web_api.interfaces import (
register_http_routes,
register_socketio_handlers,
)
CleanupHandler = Callable[[], None]
@dataclass(frozen=True)
class AppModuleBootstrapResult:
"""Public app-module contract consumed by ``apps.web_api.app``."""
app: Flask
socketio: SocketIO
cleanup_handler: CleanupHandler
search_hooks: SearchHookSource
def bootstrap_app_module(
*,
previous_cleanup_handler: CleanupHandler | None = None,
) -> AppModuleBootstrapResult:
"""Assemble the Flask app module using extracted bootstrap helpers."""
app, socketio = create_app()
runtime_services = runtime_bootstrap.build_runtime_services(socketio)
cleanup_handler = register_reload_safe_cleanup_handler(
runtime_services.cleanup_handler,
previous_cleanup_handler,
)
search_hooks = runtime_services.search_dispatch_runtime
route_search_submitter = runtime_bootstrap.build_http_route_search_request_submitter(
runtime_services=runtime_services,
search_hooks=search_hooks,
)
route_dependencies = runtime_bootstrap.build_http_route_dependencies(
runtime_services=runtime_services,
frontend_dev_server_url=resolve_frontend_dev_server_url,
socketio=socketio,
submit_search_request=route_search_submitter,
)
socket_event_dependencies = runtime_bootstrap.build_socket_event_dependencies(
runtime_services=runtime_services,
)
register_http_routes(app, route_dependencies)
register_socketio_handlers(socketio, socket_event_dependencies)
return AppModuleBootstrapResult(
app=app,
socketio=socketio,
cleanup_handler=cleanup_handler,
search_hooks=search_hooks,
)
__all__ = [
"AppModuleBootstrapResult",
"bootstrap_app_module",
]