Compare commits

...

2 Commits

Author SHA1 Message Date
mindesbunister
8cfb13f728 Fix container stability: Add restart policy and improve cleanup system
- Add restart: unless-stopped to docker-compose.dev.yml for automatic container restart
- Fix automated cleanup service to respect DISABLE_AUTO_CLEANUP environment variable
- Add process ID protection to prevent killing main Node.js process
- Update health check to use wget instead of curl
- Container now stays running reliably with proper cleanup controls
2025-07-26 10:15:58 +02:00
mindesbunister
8a71e0f748 🔧 FIX: SL Learner database model name - use ai_learning_data instead of aILearningData
- Fixed all database access calls to use correct snake_case model name
- Resolves 'Cannot read properties of undefined (reading findMany)' errors
- SL Learner can now properly access the database for pattern analysis
- Database operations for decision recording now working correctly
2025-07-25 23:52:17 +02:00
4 changed files with 20 additions and 63 deletions

View File

@@ -1,8 +1,7 @@
version: '2.4'
services:
app:
container_name: trader_dev
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
@@ -52,8 +51,6 @@ services:
- ./lib:/app/lib:cached
- ./components:/app/components:cached
- ./package.json:/app/package.json:ro
# Mount root JavaScript files for Enhanced Risk Manager
- ./start-enhanced-risk-manager.js:/app/start-enhanced-risk-manager.js:ro
# Port mapping for development
ports:
@@ -69,46 +66,3 @@ services:
timeout: 5s
retries: 2
start_period: 15s
# Enhanced Risk Manager as separate service
risk_manager:
container_name: enhanced_risk_manager
build:
context: .
dockerfile: Dockerfile
args:
- BUILDKIT_INLINE_CACHE=1
- NODE_VERSION=20.11.1
- PNPM_VERSION=8.15.1
# Override entrypoint and command to run Enhanced Risk Manager directly
entrypoint: []
command: ["node", "start-enhanced-risk-manager.js"]
# Enhanced Risk Manager environment
environment:
- NODE_ENV=development
- DOCKER_ENV=true
- DATABASE_URL=file:./prisma/dev.db
- TZ=Europe/Berlin
# Load environment variables from .env file
env_file:
- .env
# Enhanced Risk Manager volumes
volumes:
- ./lib:/app/lib:cached
- ./prisma:/app/prisma:cached
- ./start-enhanced-risk-manager.js:/app/start-enhanced-risk-manager.js:ro
# Working directory
working_dir: /app
# Depends on the main app being healthy
depends_on:
app:
condition: service_healthy
# Restart policy
restart: unless-stopped

View File

@@ -53,19 +53,20 @@ export class AutomatedCleanupService {
console.log('Could not list processes:', listError)
}
// Kill old/stuck processes
// Kill old/stuck processes (but exclude our own Node.js process)
const currentPid = process.pid
const killCommands = [
// Graceful shutdown first
'pkill -TERM -f "chromium.*--remote-debugging-port" 2>/dev/null || true',
'pkill -TERM -f "chromium.*--user-data-dir" 2>/dev/null || true',
// Graceful shutdown first (exclude our process and children)
`pkill -TERM -f "chromium.*--remote-debugging-port" | grep -v ${currentPid} 2>/dev/null || true`,
`pkill -TERM -f "chromium.*--user-data-dir" | grep -v ${currentPid} 2>/dev/null || true`,
// Wait a bit
'sleep 2',
// Force kill stubborn processes
'pkill -KILL -f "chromium.*--remote-debugging-port" 2>/dev/null || true',
'pkill -KILL -f "chromium.*--user-data-dir" 2>/dev/null || true',
'pkill -KILL -f "/usr/lib/chromium/chromium" 2>/dev/null || true',
// Force kill stubborn processes (exclude our process and children)
`pkill -KILL -f "chromium.*--remote-debugging-port" | grep -v ${currentPid} 2>/dev/null || true`,
`pkill -KILL -f "chromium.*--user-data-dir" | grep -v ${currentPid} 2>/dev/null || true`,
`pkill -KILL -f "/usr/lib/chromium/chromium" | grep -v ${currentPid} 2>/dev/null || true`,
// Clean up zombies
'pkill -9 -f "chromium.*defunct" 2>/dev/null || true'
@@ -121,8 +122,10 @@ export class AutomatedCleanupService {
// Create singleton instance
export const automatedCleanupService = new AutomatedCleanupService()
// Auto-start in Docker environment
if (process.env.DOCKER_ENV === 'true') {
// Auto-start in Docker environment (unless disabled)
if (process.env.DOCKER_ENV === 'true' && process.env.DISABLE_AUTO_CLEANUP !== 'true') {
console.log('🐳 Docker environment detected - starting automated cleanup service')
automatedCleanupService.start(30000) // Every 30 seconds in Docker
} else if (process.env.DOCKER_ENV === 'true' && process.env.DISABLE_AUTO_CLEANUP === 'true') {
console.log('🐳 Docker environment detected but auto cleanup is disabled via DISABLE_AUTO_CLEANUP=true')
}

View File

@@ -45,7 +45,7 @@ class SimplifiedStopLossLearner {
};
const prisma = await getDB();
const record = await prisma.aILearningData.create({
const record = await prisma.ai_learning_data.create({
data: decision
});
@@ -65,7 +65,7 @@ class SimplifiedStopLossLearner {
async updateDecisionOutcome(decisionId, outcomeData) {
try {
const prisma = await getDB();
await prisma.aILearningData.update({
await prisma.ai_learning_data.update({
where: { id: decisionId },
data: {
outcome: outcomeData.outcome,
@@ -93,7 +93,7 @@ class SimplifiedStopLossLearner {
async analyzeDecisionPatterns() {
try {
const prisma = await getDB();
const decisions = await prisma.aILearningData.findMany({
const decisions = await prisma.ai_learning_data.findMany({
where: {
analysisData: {
string_contains: '"type":"STOP_LOSS_DECISION"'
@@ -159,7 +159,7 @@ class SimplifiedStopLossLearner {
// Find similar situations
const prisma = await getDB();
const similarDecisions = await prisma.aILearningData.findMany({
const similarDecisions = await prisma.ai_learning_data.findMany({
where: {
analysisData: {
string_contains: '"type":"STOP_LOSS_DECISION"'
@@ -237,7 +237,7 @@ class SimplifiedStopLossLearner {
async getLearningStatus() {
try {
const prisma = await getDB();
const totalDecisions = await prisma.aILearningData.count({
const totalDecisions = await prisma.ai_learning_data.count({
where: {
analysisData: {
string_contains: '"type":"STOP_LOSS_DECISION"'
@@ -245,7 +245,7 @@ class SimplifiedStopLossLearner {
}
});
const recentDecisions = await prisma.aILearningData.count({
const recentDecisions = await prisma.ai_learning_data.count({
where: {
analysisData: {
string_contains: '"type":"STOP_LOSS_DECISION"'

Binary file not shown.