/ db / migrations / 059-monitor-tiered-scheduling.sql
059-monitor-tiered-scheduling.sql
 1  -- Migration 059: Tiered Monitor Scheduling
 2  -- Replaces single watchdog cron job with 3 tiered monitoring jobs:
 3  --   Tier 1: Process Guardian (1 min) - direct function, works without agent system
 4  --   Tier 2: Pipeline Monitor (5 min) - creates agent tasks for Monitor
 5  --   Tier 3: System Health (30 min) - creates agent tasks for heavier checks
 6  
 7  -- Tier 1: Process Guardian (direct function, every 1 minute)
 8  INSERT OR REPLACE INTO cron_jobs
 9    (name, task_key, description, handler_type, handler_value,
10     interval_value, interval_unit, enabled)
11  VALUES
12    ('Process Guardian', 'processGuardian',
13     'Service restarts, circuit breaker, clearance cycle detection',
14     'function', 'processGuardian', 1, 'minutes', 1);
15  
16  -- Tier 2: Pipeline Monitor (creates agent task, every 5 minutes)
17  INSERT OR REPLACE INTO cron_jobs
18    (name, task_key, description, handler_type, handler_value,
19     interval_value, interval_unit, enabled)
20  VALUES
21    ('Pipeline Monitor', 'monitorPipeline',
22     'Bottlenecks, blocked tasks, loops, log scanning, compliance',
23     'function', 'monitorPipeline', 5, 'minutes', 1);
24  
25  -- Tier 3: System Health (creates agent tasks, every 30 minutes)
26  INSERT OR REPLACE INTO cron_jobs
27    (name, task_key, description, handler_type, handler_value,
28     interval_value, interval_unit, enabled)
29  VALUES
30    ('System Health', 'monitorSystem',
31     'Agent health, queue depth, throughput, anomalies, SLO compliance',
32     'function', 'monitorSystem', 30, 'minutes', 1);
33  
34  -- Remove old watchdog job if it exists
35  DELETE FROM cron_jobs WHERE task_key = 'watchdog';