this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: only fetch daily kitten on startup if past 10 AM Central

Previously, restarting the app before 10 AM would trigger an immediate
kitten fetch because none existed for the day yet. Now the startup
check respects the scheduled 10 AM time and only fetches if the
scheduled time has passed.

+22 -5
+22 -5
internal/scheduler/scheduler.go
··· 53 53 s.cron.Start() 54 54 slog.Info("Scheduler started", "nextRun", s.cron.Entries()[0].Next) 55 55 56 - // Check if we need to fetch today's cat on startup 57 - go s.checkStartupCat(ctx) 56 + // Check if we need to fetch today's kitten on startup 57 + go s.checkStartupKitten(ctx) 58 58 59 59 return nil 60 60 } ··· 67 67 slog.Info("Scheduler stopped") 68 68 } 69 69 70 - // checkStartupCat checks if today's cat needs to be fetched on startup. 71 - func (s *Scheduler) checkStartupCat(ctx context.Context) { 70 + // checkStartupKitten checks if today's kitten needs to be fetched on startup. 71 + // Only fetches if it's past 10 AM Central and no kitten exists for today. 72 + func (s *Scheduler) checkStartupKitten(ctx context.Context) { 73 + // Check if it's past 10 AM Central Time 74 + loc, err := time.LoadLocation("America/Chicago") 75 + if err != nil { 76 + slog.Warn("Failed to load America/Chicago timezone for startup check", "error", err) 77 + return 78 + } 79 + 80 + now := time.Now().In(loc) 81 + tenAM := time.Date(now.Year(), now.Month(), now.Day(), 10, 0, 0, 0, loc) 82 + 83 + if now.Before(tenAM) { 84 + slog.Info("Before 10 AM Central, skipping startup kitten check", 85 + "currentTime", now.Format("15:04:05 MST")) 86 + return 87 + } 88 + 72 89 existing, err := s.store.GetTodayImageByLink(ctx, catAASUser) 73 90 if err != nil { 74 91 slog.Warn("Failed to check for existing daily cat on startup", "error", err) ··· 76 93 } 77 94 78 95 if existing == nil { 79 - slog.Info("No daily kitten for today, fetching now") 96 + slog.Info("No daily kitten for today and past 10 AM, fetching now") 80 97 s.fetchDailyCatWithRetry(ctx) 81 98 } else { 82 99 slog.Info("Daily kitten already exists", "imageID", existing.ID)