50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""
|
|
backend/workers/worker_fixed_assets.py
|
|
|
|
用途:固定资产快照同步独立 worker 入口(迁出 Web 进程内 daemon 线程)。
|
|
依赖:app.create_app、FixedAssetsSnapshotService.run_worker_forever。
|
|
逻辑:按 FIXED_ASSETS_SYNC_* 配置做 boot 补齐与每日定点同步;Compose 服务 hxops-fixed-assets-worker。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
_backend_root = Path(__file__).resolve().parents[1]
|
|
if str(_backend_root) not in sys.path:
|
|
sys.path.insert(0, str(_backend_root))
|
|
|
|
from app import create_app
|
|
from app.services.fixed_assets_snapshot import FixedAssetsSnapshotService
|
|
|
|
|
|
def _resolve_config_name() -> str:
|
|
"""与 worker.py 对齐的环境配置解析。"""
|
|
explicit = (os.getenv('APP_CONFIG') or '').strip().lower()
|
|
if explicit:
|
|
if explicit in ('testing', 'test'):
|
|
return 'test'
|
|
return explicit
|
|
|
|
env_name = (os.getenv('ENV_NAME') or os.getenv('FLASK_ENV') or 'production').strip().lower()
|
|
mapping = {
|
|
'dev': 'development',
|
|
'development': 'development',
|
|
'test': 'production',
|
|
'prod': 'production',
|
|
'production': 'production',
|
|
'testing': 'test',
|
|
}
|
|
return mapping.get(env_name, 'production')
|
|
|
|
|
|
def main() -> None:
|
|
"""启动固资快照 worker 主循环(阻塞)。"""
|
|
app = create_app(_resolve_config_name())
|
|
FixedAssetsSnapshotService.run_worker_forever(app)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|