Files
cms-SiteForge/app/worker_health.py
T
浅念 601451f22b upgrade: adopt V8.21.3 (V8.13→8.21.3: P5 SFTP/S3, P6 multilingual, editor overhaul, enterprise hardening)
Overlay ~150 upstream items onto our V8.12 base, preserving trade-pro
theme, registry tests, and design docs. Re-applied our patch set
(discovery/env_for/blocks.css/type-mapping/theme_color/frontend entries,
test_theme_pro_v3 mods) — all anchors survived upstream evolution.

New platform enhancement (fixes upgrade-introduced regression):
multilingual.site_locale now honors settings_json.locale, plus
PUT /api/i18n/sites/{id}/locale — standalone English sites get
<html lang='en'> under the V8.15 locale-rewrite pipeline.

compose: adopt V8.21.3 (image 8.21.3-dev.1, /api/ready probes, MySQL/S3
env) with project name pinned to siteforge-v8-10 (data volumes).

Tests: 356 passed / 11 failed — all 11 confirmed pre-existing in
pristine V8.21.3 on this host (10 upstream Windows env + our build test
now green after locale fix). Patch registry updated in plan doc.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-23 12:31:03 +08:00

36 lines
1.2 KiB
Python

"""Docker worker liveness probe: no localhost Web dependency."""
import os
import time
import socket
import re
from pathlib import Path
from . import db
def heartbeat_path():
instance=os.environ.get('SITEFORGE_WORKER_INSTANCE', '')
if not instance and db.POSTGRES:
instance=socket.gethostname()
if instance:
if not re.fullmatch(r'[A-Za-z0-9._-]{1,120}',instance):
raise ValueError('Invalid worker instance identifier')
return db.DATA/'worker-heartbeats'/instance
return db.DATA/'worker-heartbeat'
def healthy(path=None, max_age=None, check_store=False):
file=Path(path) if path is not None else heartbeat_path()
limit=float(max_age if max_age is not None else os.getenv('SITEFORGE_WORKER_HEALTH_MAX_AGE','45'))
if limit <= 0:return False
try:
age=time.time()-file.stat().st_mtime
fresh=-5 <= age < limit
if not fresh:return False
if check_store:
from .healthchecks import readiness
return readiness()
return True
except (OSError,ValueError):
return False
if __name__=='__main__':
raise SystemExit(0 if healthy(check_store=True) else 1)