CRITICAL FIX (Nov 30, 2025):
- Dashboard showed 'idle' despite 22+ worker processes running
- Root cause: SSH-based worker detection timing out
- Solution: Check database for running chunks FIRST
Changes:
1. app/api/cluster/status/route.ts:
- Query exploration database before SSH detection
- If running chunks exist, mark workers 'active' even if SSH fails
- Override worker status: 'offline' → 'active' when chunks running
- Log: '✅ Cluster status: ACTIVE (database shows running chunks)'
- Database is source of truth, SSH only for supplementary metrics
2. app/cluster/page.tsx:
- Stop button ALREADY EXISTS (conditionally shown)
- Shows Start when status='idle', Stop when status='active'
- No code changes needed - fixed by status detection
Result:
- Dashboard now shows 'ACTIVE' with 2 workers (correct)
- Workers show 'active' status (was 'offline')
- Stop button automatically visible when cluster active
- System resilient to SSH timeouts/network issues
Verified:
- Container restarted: Nov 30 21:18 UTC
- API tested: Returns status='active', activeWorkers=2
- Logs confirm: Database-first logic working
- Workers confirmed running: 22+ processes on worker1, workers on worker2
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
|
|
def rma(series: pd.Series, length: int) -> pd.Series:
|
|
alpha = 1.0 / length
|
|
result = series.astype(float).copy()
|
|
for i in range(1, len(series)):
|
|
prev = result.iat[i - 1]
|
|
curr = series.iat[i]
|
|
result.iat[i] = alpha * curr + (1 - alpha) * prev
|
|
return result
|
|
|
|
|
|
def calculate_atr(df: pd.DataFrame, length: int) -> pd.Series:
|
|
high, low, close = df["high"], df["low"], df["close"]
|
|
tr = pd.concat([
|
|
(high - low),
|
|
(high - close.shift(1)).abs(),
|
|
(low - close.shift(1)).abs(),
|
|
], axis=1).max(axis=1)
|
|
tr.iloc[0] = (high.iloc[0] - low.iloc[0])
|
|
return rma(tr, length)
|
|
|
|
|
|
def calculate_adx(df: pd.DataFrame, length: int) -> pd.Series:
|
|
high, low, close = df["high"], df["low"], df["close"]
|
|
up_move = high.diff()
|
|
down_move = -low.diff()
|
|
plus_dm = np.where((up_move > down_move) & (up_move > 0), up_move, 0.0)
|
|
minus_dm = np.where((down_move > up_move) & (down_move > 0), down_move, 0.0)
|
|
tr = pd.concat([
|
|
(high - low),
|
|
(high - close.shift(1)).abs(),
|
|
(low - close.shift(1)).abs(),
|
|
], axis=1).max(axis=1)
|
|
tr.iloc[0] = (high.iloc[0] - low.iloc[0])
|
|
|
|
atr = rma(tr, length)
|
|
# CRITICAL FIX: Preserve index when creating Series to avoid doubling on division
|
|
plus_di = 100.0 * rma(pd.Series(plus_dm, index=df.index), length) / atr
|
|
minus_di = 100.0 * rma(pd.Series(minus_dm, index=df.index), length) / atr
|
|
dx = 100.0 * (plus_di - minus_di).abs() / (plus_di + minus_di).replace(0, np.nan)
|
|
dx = dx.fillna(0.0)
|
|
return rma(dx, length)
|