logs: add some log to fix scheduling errors
This commit is contained in:
@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user