Skip to content

Runtime topology (web + worker) ​

Version: 1.5
Date: 2026-11-25
Status: Working baseline (DEC-016 / DEC-017 CONFIRMED)

Quyết định ​

Hạng mụcGiá trị
FrameworkNext.js (App Router) — Admin UI (+ platform-ui) và HTTP API cùng app
Jobsnode-cron UTC trên worker — không chạy trong process web
Bootstrap jobsJobs orchestrator (main) → đọc config → đăng ký child jobs (DEC-017)
Multi-worker lockRedis per child job (jobs.lock.*)
CodebaseMột repo / shared lib; hai entrypoint deploy

Hai service Swarm (ví dụ tên) ​

ServiceVai tròCron children
minap-fileNext.js standalone — UI admin + APIKhông
minap-file-workerProcess Node: start orchestrator + (sau đó) child jobsCó — qua orchestrator
text
Docker image PRIMARY (Dockerfile → minap-file)
├── web:    node server.js           → minap-file
└── worker: node …/worker.js         → minap-file-worker
              └── start JobsOrchestrator only
                    ├── load config (cron + locks + …)
                    ├── register child node-cron tasks
                    └── reload_interval → diff config → re-register

Docs image (Dockerfile.docs → minap-docs-file) — VitePress static / Nginx
  scripts: production.docs.build.sh · production.docs.tag-and-push.sh
  npm:     docker:docs:build · docker:docs:push
  • Scale web độc lập.
  • Scale worker ≥ 2: Redis lock per child.
  • FS_ROLE=web|worker.
  • Không đăng ký child cron trong Next instrumentation.ts.
  • Docs site lab tách image (minap-docs-file); không dùng chung production.build.sh với service (hub /docs-sites, framework/15 §12.0).

Jobs orchestrator (DEC-017) ​

Vấn đề: mọi child gần như có schedule riêng trong DB (*.*_cron). Không hard-code schedule(...) ngay lúc process start.

Luồng:

  1. Worker process start → chỉ chạy main = jobs orchestrator.
  2. Orchestrator đọc bảng config (và Infisical nếu cần).
  3. Đăng ký lần lượt child: temp GC, migrate, purge, variant GC — mỗi cái một expression từ config + Redis lock tương ứng. Thân tick: per-item isolation (RULE-015) — xem E.03 §5.
  4. Phát hiện đổi (Q-BR-064):
    • Poll jobs.orchestrator.reload_interval — diff snapshot theo watched_key_prefixes → re-register
    • Reload now — ops/API (admin) gọi re-register ngay, không chờ poll
  5. Re-register = stop schedules cũ + đăng ký lại children (không bắt buộc restart container).

Config keys: 03-config-keys — jobs.orchestrator.*, jobs.lock.*, temp.cleanup_cron, local.migrate_cron, …

Phân công xử lý ​

ViệcChạy ở
Upload temp, promote (+ ffmpeg cover), GET variant/original, ops HTTPweb
Jobs orchestrator + child cronsworker
Đọc config / Infisical / minap_fileCả hai (shared)

Redis ​

  • Lock per child job — không thay Postgres metadata.
  • Keys/TTL: jobs.lock.* trong config.
  • URL qua Infisical.

Admin UI (hướng) ​

Stats + settings trên Next + platform-ui; đổi cron/lock → poll phát hiện hoặc bấm/gọi reload now.

Liên quan ​

  • Jobs SoT: lifecycle/03
  • DEC: overview/03
  • Disk/secrets: ops/02
  • Tham chiếu tạm (tms-file / vams-storage-sync — pattern Next+cron+Redis, không thay SoT):
    platform-file/.minap/discovery/file-service-docs/reference-tms-vams-next-cron.md

platform-file/docs = SoT chi tiết File Service · hub platform-docs giữ overview + ref