Add photo backfill for failed dinners without a photo
CI / ci (pull_request) Failing after 10m12s
CI / ci (push) Successful in 11m35s

Task 36c40130-a69a-46ed-a047-2cdc5ee2d2e0 (Feature 23, task 1 of 2).

A backfill_dinner_photos job grounds, by name with the existing
recipes.Grounder.Ground, every unarchived dinner whose grounding failed
and that has no photo and no pasted recipe_url. Ground already tries the
ranked candidates best first and keeps the first whose photo caches and
whose ingredients normalize, reusing stored recipes and photos. Success
records the recipe and photo as grounded; a failure leaves the dinner
failed with the new grounding_error for the fix-recipe flow, without
stopping its siblings. Writes are guarded on status, photo and
grounding_revision, so grounded, manual, pending, renamed and archived
dinners are never touched.

POST /api/v1/settings/photo-backfill starts a full pass and answers 202
with the job id; the kind is service-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 20:53:58 -04:00
co-authored by Claude Opus 5.5
parent fd087e0ba3
commit ec718024a1
12 changed files with 685 additions and 3 deletions
+12 -2
View File
@@ -138,6 +138,8 @@ type Service struct {
grounder *recipes.Grounder
logger *slog.Logger
groundJob *jobs.Kind[GroundJob]
// backfillJob enqueues KindBackfillPhotos jobs.
backfillJob *jobs.Kind[BackfillJob]
// wake is called after every committed change to a dinner's method or
// minutes, which can move its crock-pot start reminder.
wake func()
@@ -162,8 +164,8 @@ type Service struct {
// NewService returns a service over st that grounds dinners with grounder,
// calls wake (the scheduler's Wake) after every committed change to a
// dinner's method or minutes, and registers the KindGroundDinner job on
// runner, which must not have started yet.
// dinner's method or minutes, and registers the KindGroundDinner and
// KindBackfillPhotos jobs on runner, which must not have started yet.
func NewService(st *store.Store, grounder *recipes.Grounder, runner *jobs.Runner, wake func(), logger *slog.Logger) (*Service, error) {
switch {
case st == nil:
@@ -184,6 +186,14 @@ func NewService(st *store.Store, grounder *recipes.Grounder, runner *jobs.Runner
return nil, err
}
s.groundJob = kind
backfill, err := jobs.Register(runner, KindBackfillPhotos, s.runBackfillJob)
if err != nil {
return nil, err
}
if err := backfill.ServiceOnly(); err != nil {
return nil, err
}
s.backfillJob = backfill
return s, nil
}