mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 00:50:46 +08:00
fix(startup): defer UME alarm sync so /health is ready quickly
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
d05b64b4c1
commit
f562f50953
2 changed files with 20 additions and 5 deletions
|
|
@ -815,9 +815,23 @@ def on_startup() -> None:
|
||||||
last_error=f"startup_thread_init_failed: {str(exc)[:180]}",
|
last_error=f"startup_thread_init_failed: {str(exc)[:180]}",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
_run_startup_alarm_sync_before_ws()
|
|
||||||
|
def _startup_alarm_sync_worker() -> None:
|
||||||
|
try:
|
||||||
|
_run_startup_alarm_sync_before_ws()
|
||||||
|
except Exception as exc:
|
||||||
|
_schedule_log.exception("startup: alarm sync before WSS failed: %s", exc)
|
||||||
|
complete_startup_alarm_sync_gate()
|
||||||
|
|
||||||
|
# Do not block HTTP /health on slow UME REST pull; WSS waits on startup_alarm_sync_gate.
|
||||||
|
t_startup_sync = threading.Thread(
|
||||||
|
target=_startup_alarm_sync_worker,
|
||||||
|
name="ume-startup-alarm-sync",
|
||||||
|
daemon=True,
|
||||||
|
)
|
||||||
|
t_startup_sync.start()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_schedule_log.exception("startup: alarm sync before WSS failed: %s", exc)
|
_schedule_log.exception("startup: alarm sync thread init failed: %s", exc)
|
||||||
complete_startup_alarm_sync_gate()
|
complete_startup_alarm_sync_gate()
|
||||||
try:
|
try:
|
||||||
if bool(getattr(settings, "ume_sync_alarms_current_enabled", True)):
|
if bool(getattr(settings, "ume_sync_alarms_current_enabled", True)):
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ function Show-LogTail {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Test-NetxApiListening {
|
function Test-NetxApiListening {
|
||||||
param([string]$HostName, [int]$LocalPort, [int]$WaitSec = 12)
|
param([string]$HostName, [int]$LocalPort, [int]$WaitSec = 45)
|
||||||
$deadline = (Get-Date).AddSeconds($WaitSec)
|
$deadline = (Get-Date).AddSeconds($WaitSec)
|
||||||
while ((Get-Date) -lt $deadline) {
|
while ((Get-Date) -lt $deadline) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -135,8 +135,9 @@ if ($Background) {
|
||||||
Show-LogTail -Path $logFile
|
Show-LogTail -Path $logFile
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
if (-not (Test-NetxApiListening -HostName $BindHost -LocalPort $Port)) {
|
$healthWaitSec = 45
|
||||||
Write-Host "[ERR] Port $Port not listening /health not OK within 12s (PID may still be starting or stuck on DB)." -ForegroundColor Red
|
if (-not (Test-NetxApiListening -HostName $BindHost -LocalPort $Port -WaitSec $healthWaitSec)) {
|
||||||
|
Write-Host "[ERR] Port $Port not listening /health not OK within ${healthWaitSec}s (process may be stuck on DB or schema migration)." -ForegroundColor Red
|
||||||
Show-LogTail -Path $errFile
|
Show-LogTail -Path $errFile
|
||||||
Show-LogTail -Path $logFile
|
Show-LogTail -Path $logFile
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue