logs: add some log to fix scheduling errors

This commit is contained in:
2026-04-28 07:08:24 +02:00
parent 9780311cd0
commit 087bcab16b
4 changed files with 113 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package scheduler
import (
"context"
"fmt"
"sync"
"github.com/robfig/cron/v3"
"github.com/tradarr/backend/internal/ai"
@ -16,6 +17,7 @@ type Scheduler struct {
pipeline *ai.Pipeline
repo *models.Repository
entryIDs []cron.EntryID
running sync.Mutex
}
func New(registry *scraper.Registry, pipeline *ai.Pipeline, repo *models.Repository) *Scheduler {
@ -78,6 +80,17 @@ func (s *Scheduler) loadSchedule() error {
}
func (s *Scheduler) run() {
if !s.running.TryLock() {
fmt.Println("scheduler: previous cycle still running, skipping")
return
}
defer s.running.Unlock()
defer func() {
if r := recover(); r != nil {
fmt.Printf("scheduler: panic recovered: %v\n", r)
}
}()
fmt.Println("scheduler: starting scraping cycle")
if err := s.registry.RunAll(); err != nil {
fmt.Printf("scheduler scrape error: %v\n", err)
@ -87,4 +100,5 @@ func (s *Scheduler) run() {
if err := s.pipeline.GenerateForAll(context.Background()); err != nil {
fmt.Printf("scheduler summary error: %v\n", err)
}
fmt.Println("scheduler: cycle complete")
}