2024-01-23 20:55:20 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2024-05-31 15:37:56 +08:00
|
|
|
import traceback
|
|
|
|
|
2024-01-23 20:55:20 +08:00
|
|
|
from . import app
|
|
|
|
from ..audit import identifier
|
2024-03-02 16:37:30 +08:00
|
|
|
from . import stage
|
2024-03-03 16:34:59 +08:00
|
|
|
|
|
|
|
# 引入启动阶段实现以便注册
|
2024-07-03 17:34:23 +08:00
|
|
|
from .stages import load_config, setup_logger, build_app, migrate, show_notes
|
2024-01-23 20:55:20 +08:00
|
|
|
|
|
|
|
|
2024-03-02 16:37:30 +08:00
|
|
|
stage_order = [
|
|
|
|
"LoadConfigStage",
|
2024-03-16 20:27:17 +08:00
|
|
|
"MigrationStage",
|
2024-03-02 16:37:30 +08:00
|
|
|
"SetupLoggerStage",
|
2024-07-03 17:34:23 +08:00
|
|
|
"BuildAppStage",
|
|
|
|
"ShowNotesStage"
|
2024-03-02 16:37:30 +08:00
|
|
|
]
|
2024-01-23 20:55:20 +08:00
|
|
|
|
|
|
|
|
2024-03-02 16:37:30 +08:00
|
|
|
async def make_app() -> app.Application:
|
2024-01-23 20:55:20 +08:00
|
|
|
|
2024-03-02 16:37:30 +08:00
|
|
|
# 生成标识符
|
|
|
|
identifier.init()
|
2024-01-23 20:55:20 +08:00
|
|
|
|
|
|
|
ap = app.Application()
|
2024-01-26 15:51:49 +08:00
|
|
|
|
2024-03-03 16:34:59 +08:00
|
|
|
# 执行启动阶段
|
2024-03-02 16:37:30 +08:00
|
|
|
for stage_name in stage_order:
|
|
|
|
stage_cls = stage.preregistered_stages[stage_name]
|
|
|
|
stage_inst = stage_cls()
|
2024-05-29 21:11:21 +08:00
|
|
|
|
2024-03-02 16:37:30 +08:00
|
|
|
await stage_inst.run(ap)
|
2024-01-31 00:02:19 +08:00
|
|
|
|
2024-01-27 21:50:40 +08:00
|
|
|
await ap.initialize()
|
2024-01-23 20:55:20 +08:00
|
|
|
|
|
|
|
return ap
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
2024-05-29 21:11:21 +08:00
|
|
|
try:
|
|
|
|
app_inst = await make_app()
|
|
|
|
await app_inst.run()
|
|
|
|
except Exception as e:
|
2024-05-31 15:37:56 +08:00
|
|
|
traceback.print_exc()
|