Skip to content

Sprint 1: Implement Background Monitoring Scheduler #13

@CLoaKY233

Description

@CLoaKY233

Epic: PingSpider MVP - Distributed Uptime & Latency Monitor

Sprint: 1

Story Points: 8

Description

Create a background task scheduler that periodically checks all registered endpoints and stores metrics in SurrealDB.

Acceptance Criteria

  • Create src/monitoring/scheduler.rs with async task scheduler
  • Load all active endpoints from database on startup
  • Schedule health checks based on each endpoint's check_interval
  • Execute checks concurrently (use tokio::spawn for parallelization)
  • Store check results in metrics table
  • Handle endpoint addition/removal dynamically
  • Implement graceful shutdown on SIGTERM/SIGINT
  • Add scheduler status endpoint GET /api/scheduler/status

Technical Notes

  • Use tokio::time::interval for periodic execution
  • Use tokio::select! for shutdown handling
  • Limit concurrent checks to prevent resource exhaustion (e.g., max 100 concurrent)
  • Use Arc<RwLock<HashMap>> or similar for in-memory endpoint tracking
  • Consider using tokio-cron-scheduler for more complex scheduling

Scheduler Logic Flow

  1. On startup: Load all endpoints from DB
  2. For each endpoint: Spawn a task with its check_interval
  3. On interval tick: Execute health check
  4. Store result in metrics table
  5. Update endpoint status if changed
  6. On shutdown: Cancel all tasks gracefully

Dependencies

  • tokio with signal feature for graceful shutdown
  • Optional: tokio-cron-scheduler crate

Files to Create/Modify

  • src/monitoring/scheduler.rs
  • src/sys/init.rs (start scheduler on app init)
  • src/rts/scheduler.rs (status endpoint handler)

Definition of Done

  • Scheduler runs all endpoint checks on schedule
  • Metrics correctly stored in SurrealDB
  • No memory leaks or resource exhaustion
  • Graceful shutdown works
  • Load testing completed (100+ endpoints)
  • Code reviewed and merged to main

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions