diff --git a/app/api/trading/check-risk/route.ts b/app/api/trading/check-risk/route.ts index 4d1e961..c51c6bd 100644 --- a/app/api/trading/check-risk/route.ts +++ b/app/api/trading/check-risk/route.ts @@ -6,7 +6,7 @@ */ import { NextRequest, NextResponse } from 'next/server' -import { getMergedConfig, TradingConfig, getMinQualityScoreForDirection } from '@/config/trading' +import { getMergedConfig, TradingConfig, getMinQualityScoreForDirection, normalizeTradingViewSymbol } from '@/config/trading' import { getInitializedPositionManager, ActiveTrade } from '@/lib/trading/position-manager' import { getLastTradeTime, getLastTradeTimeForSymbol, getTradesInLastHour, getTodayPnL, createBlockedSignal } from '@/lib/database/trades' import { getPythPriceMonitor } from '@/lib/pyth/price-monitor' @@ -432,9 +432,16 @@ export async function POST(request: NextRequest): Promise /tmp/{chunk_id}.log 2>&1 &" + subprocess.Popen(bg_cmd, shell=True) + print(f"āœ“ {chunk_id} launched on {worker_name} (background)") - except subprocess.TimeoutExpired: - print(f"āš ļø {chunk_id} timed out on {worker_name}") - mark_failed(chunk_id) except Exception as e: - print(f"āŒ Error running {chunk_id} on {worker_name}: {e}") + print(f"āŒ Error launching {chunk_id} on {worker_name}: {e}") mark_failed(chunk_id) def mark_complete(chunk_id: str): @@ -141,6 +128,47 @@ def mark_failed(chunk_id: str): conn.commit() conn.close() +def check_completions(): + """Check for completed chunks by looking for output files""" + conn = sqlite3.connect(DB_PATH) + cursor = conn.cursor() + + # Get all running chunks + cursor.execute(""" + SELECT id, assigned_worker FROM v9_advanced_chunks + WHERE status = 'running' + """) + + running_chunks = cursor.fetchall() + + for chunk_id, worker_name in running_chunks: + output_file = Path(f"distributed_results/{chunk_id}_results.csv") + + # Check if output file exists locally (would be copied back) + if output_file.exists(): + print(f"āœ“ {chunk_id} completed (found output file)") + mark_complete(chunk_id) + else: + # Check on remote worker + worker = WORKERS[worker_name] + remote_output = f"{worker['workspace']}/distributed_results/{chunk_id}_results.csv" + + if 'ssh_hop' in worker: + check_cmd = f"ssh {worker['ssh_hop']} \"ssh {worker['host']} 'test -f {remote_output} && echo EXISTS'\"" + else: + check_cmd = f"ssh {worker['host']} 'test -f {remote_output} && echo EXISTS'" + + try: + result = subprocess.run(check_cmd, shell=True, capture_output=True, text=True, timeout=10) + if result.stdout.strip() == 'EXISTS': + print(f"āœ“ {chunk_id} completed on {worker_name}") + mark_complete(chunk_id) + except Exception as e: + # If check fails, chunk might still be running + pass + + conn.close() + def main(): """Main coordinator loop""" print("="*60) @@ -175,6 +203,9 @@ def main(): print(f"Status: {completed} completed, {running} running, {pending} pending") + # Check for completed chunks + check_completions() + if pending == 0 and running == 0: print("\nāœ“ All chunks completed!") break diff --git a/docker-compose.telegram-bot.yml b/docker-compose.telegram-bot.yml index 894b621..3776b90 100644 --- a/docker-compose.telegram-bot.yml +++ b/docker-compose.telegram-bot.yml @@ -10,6 +10,7 @@ services: env_file: - .env.telegram-bot dns: + - 9.9.9.9 - 8.8.8.8 - 8.8.4.4 environment: