Files
MealQuest/internal/suggest/schedule.go
T
dev_agentandClaude Opus 5.5 94b1378a7b
CI / ci (push) Successful in 9m25s
CI / ci (pull_request) Successful in 9m2s
Register the weekly suggestions schedule (Feature 20)
suggest.Service.WeeklySchedule fires at the household suggestions_dow and
suggestions_time (default Sunday 08:00) with period key
suggestions_weekly:YYYY-Www and starts a scheduled batch through the same
service and job as the API, via the new StartScheduledBatch(week).
StartBatch now refuses the scheduled trigger.

new_suggestions is still emitted only where Feature 19 put it, in the
transaction that stores a batch's Side quests. A scheduled batch is now
keyed new_suggestions:YYYY-Www by the week carried in its job, so a
batch caught up late keeps its own week's key; a manual batch stays keyed
by its id. The title counts the new Side quests. A batch whose AI call
fails stores nothing and sends nothing; the failure is in ai_runs.

Fake-clock tests in internal/scheduler cover one batch and one
notification per week, settings-driven fire time, AI failure, restart,
late catch-up and a batch already under way.

Maestro task 459aab71-5c3d-4853-9855-236a3602b1e0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 19:51:16 -04:00

37 lines
1.3 KiB
Go

package suggest
import (
"context"
"time"
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/household"
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/scheduler"
)
// WeeklySchedule is the suggestions_weekly schedule: at the household's
// suggestions_dow and suggestions_time it starts a scheduled batch for the
// ISO week of the fire date, its period scheduler.Weekly keys
// suggestions_weekly:YYYY-Www. The batch tells the household of the Side
// quests it adds with new_suggestions:YYYY-Www for that week, once; a batch
// that fails before adding any, as when the AI fails, sends nothing. When a
// batch is already pending or running the period starts none, and says so.
func (s *Service) WeeklySchedule() scheduler.Schedule {
return scheduler.Schedule{
Name: scheduler.SuggestionsWeekly,
Rule: func(settings household.Settings) scheduler.Rule {
return scheduler.Weekly(time.Weekday(settings.SuggestionsDow), settings.SuggestionsTime)
},
Run: func(ctx context.Context, p scheduler.Period) error {
b, err := s.StartScheduledBatch(ctx, p.Week)
if err != nil {
return err
}
if !b.Created {
s.logger.WarnContext(ctx, "scheduled suggestion batch not started: a batch is already under way",
"period", p.Key, "batch_id", b.ID, "trigger", b.Trigger)
}
return nil
},
}
}