refactor: refactor of backend
This commit is contained in:
1 parent
d4cb8c5def
commit
14e5af0c9c
55 files changed
+2251
-1805
No files matched your search
@@ -8,5 +8,6 @@
|
||||
| `worker_shipping.py` | `worker_shipping_notice.py` → `main(queues=['shipping'])` |
|
||||
| — | `worker_scheduler.py` → `main(queues=['schedule'])` |
|
||||
| —(Compose 直接用本目录单实例入口) | `worker_in_transit_transfer.py` → `main(queues=['transfer'])` |
|
||||
| —(Compose:`hxops-fixed-assets-worker`) | `worker_fixed_assets.py` → `FixedAssetsSnapshotService.run_worker_forever` |
|
||||
|
||||
本地 / Compose 请用根目录脚本,以保留 `*_WORKER_CONCURRENCY` 多进程能力。
|
||||
本地 / Compose 请用根目录脚本,以保留 `*_WORKER_CONCURRENCY` 多进程能力(固资快照为独立常驻循环,无队列并发参数)。
|
||||
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
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()
|
||||
Reference in new issue
Block a user