Skip to content

scheduler: add per-section error handling in loadSchedules() #112

@ng

Description

@ng

Problem

Currently, if any single DB query fails in loadSchedules() (e.g., the alarmSchedules query), the entire load aborts. This leaves the scheduler in a partially initialized state where some job types are scheduled but others are missing, with no clear indication to the caller.

File: src/scheduler/jobManager.ts:70-111

Impact

  • Development: Fail-fast behavior makes debugging easier
  • Production: Single table failure could prevent ALL schedules from loading

Proposed Solution

Wrap each schedule type section in its own try/catch:

async loadSchedules(): Promise<void> {
  console.log('Loading schedules from database...')

  // Temperature schedules
  try {
    const tempSchedules = await db.select().from(temperatureSchedules)
    for (const sched of tempSchedules) {
      if (sched.enabled) {
        this.scheduleTemperature(sched)
      }
    }
  } catch (error) {
    console.error('Failed to load temperature schedules:', error)
  }

  // Repeat for power, alarm, and system schedules...
  
  console.log(`Loaded ${this.scheduler.getJobs().length} scheduled jobs`)
}

Priority

Medium - Should be implemented before production deployment for better resilience

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions