feat: implement health check system (Phase 1 & 2)
Add comprehensive health monitoring for TPMJS tools that tracks both import and execution health via Railway executor service. ## Database Schema - Add HealthStatus enum (UNKNOWN, HEALTHY, BROKEN) - Add HealthCheckType enum (IMPORT, EXECUTION, FULL) - Add health fields to Tool model: - importHealth: tracks if tool can be loaded - executionHealth: tracks if tool can execute - lastHealthCheck: timestamp of last check - healthCheckError: stores error message - Add HealthCheck audit table for full history ## Core Service Create health-check-service.ts with 5 functions: 1. checkImportHealth() - Tests tool loading via /load-and-describe 2. checkExecutionHealth() - Tests execution via /execute-tool 3. generateTestParameters() - Creates minimal test params by type 4. performHealthCheck() - Full check with database updates 5. performBatchHealthCheck() - Processes tools in batches Features: - 30-second timeout per check - Skips execution if import fails - Batch processing (5 concurrent, 1s delays) - Full audit trail in HealthCheck table ## API Endpoints /api/sync/health-check (POST): - Daily cron job at 2am UTC - Checks all tools in database - Requires CRON_SECRET auth - Logs results to SyncLog table - Max duration: 5 minutes /api/tools/broken (GET): - Lists all tools with broken health status - Filters by importHealth='BROKEN' OR executionHealth='BROKEN' - Includes package metadata - Orders by lastHealthCheck DESC ## Configuration - Add RAILWAY_EXECUTOR_URL to env.ts - Add daily cron job to vercel.json - Use db:push for schema changes (existing production data) Next: Manual trigger endpoint + health filtering + UI components 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8562eb5b38
commit
148207bcaa
6 changed files with 520 additions and 1 deletions
|
|
@ -73,15 +73,25 @@ model Tool {
|
|||
// Tool Metrics
|
||||
qualityScore Decimal? @map("quality_score") @db.Decimal(3, 2) // 0.00 to 1.00
|
||||
|
||||
// Health Status Fields
|
||||
importHealth HealthStatus? @default(UNKNOWN) @map("import_health")
|
||||
executionHealth HealthStatus? @default(UNKNOWN) @map("execution_health")
|
||||
lastHealthCheck DateTime? @map("last_health_check")
|
||||
healthCheckError String? @map("health_check_error") @db.Text
|
||||
|
||||
// Timestamps
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
// Relations
|
||||
simulations Simulation[]
|
||||
simulations Simulation[]
|
||||
healthChecks HealthCheck[]
|
||||
|
||||
@@unique([packageId, exportName])
|
||||
@@index([qualityScore])
|
||||
@@index([importHealth])
|
||||
@@index([executionHealth])
|
||||
@@index([lastHealthCheck])
|
||||
@@map("tools")
|
||||
}
|
||||
|
||||
|
|
@ -186,3 +196,53 @@ model ExecutionLog {
|
|||
@@index([simulationId])
|
||||
@@map("execution_logs")
|
||||
}
|
||||
|
||||
/// HealthCheck table - tracks full audit history of health checks
|
||||
model HealthCheck {
|
||||
id String @id @default(cuid())
|
||||
|
||||
// Relations
|
||||
toolId String @map("tool_id")
|
||||
tool Tool @relation(fields: [toolId], references: [id], onDelete: Cascade)
|
||||
|
||||
// Check metadata
|
||||
checkType HealthCheckType @map("check_type")
|
||||
triggerSource String @map("trigger_source") @db.VarChar(50) // 'sync' | 'manual' | 'daily-cron'
|
||||
|
||||
// Import check results
|
||||
importStatus HealthStatus @map("import_status")
|
||||
importError String? @map("import_error") @db.Text
|
||||
importTimeMs Int? @map("import_time_ms")
|
||||
|
||||
// Execution check results
|
||||
executionStatus HealthStatus @map("execution_status")
|
||||
executionError String? @map("execution_error") @db.Text
|
||||
executionTimeMs Int? @map("execution_time_ms")
|
||||
testParameters Json? @map("test_parameters") @db.JsonB
|
||||
|
||||
// Overall status
|
||||
overallStatus HealthStatus @map("overall_status")
|
||||
|
||||
// Timestamps
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
@@index([toolId])
|
||||
@@index([checkType])
|
||||
@@index([overallStatus])
|
||||
@@index([createdAt])
|
||||
@@map("health_checks")
|
||||
}
|
||||
|
||||
/// Health status enum - tracks health check results
|
||||
enum HealthStatus {
|
||||
UNKNOWN // Not yet checked
|
||||
HEALTHY // Passed health check
|
||||
BROKEN // Failed health check
|
||||
}
|
||||
|
||||
/// Health check type enum - types of health checks performed
|
||||
enum HealthCheckType {
|
||||
IMPORT // Only import check
|
||||
EXECUTION // Only execution check
|
||||
FULL // Both import and execution
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue