From 7552e5073f1654dc9100964b132f30c01d7dd8dd Mon Sep 17 00:00:00 2001 From: vikingowl Date: Sat, 25 Apr 2026 08:42:20 +0200 Subject: [PATCH] feat(discovery): auto-trigger Pass A enrichment after crawl Run CrawlEnrich + Nominatim geocoding in the background immediately after a crawl discovers new rows. Manual triggers via the /enrichment/crawl-all endpoint remain for backfills but are no longer needed for fresh crawls. --- backend/internal/domain/discovery/service.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/internal/domain/discovery/service.go b/backend/internal/domain/discovery/service.go index e92a352..6a71d1e 100644 --- a/backend/internal/domain/discovery/service.go +++ b/backend/internal/domain/discovery/service.go @@ -293,6 +293,21 @@ func (s *Service) Crawl(ctx context.Context) (CrawlSummary, error) { } summary.Discovered++ } + + // Automatically kick off Pass A enrichment (CrawlEnrich + Nominatim) for + // all newly-inserted rows so manual triggers are not needed for fresh crawls. + // 45 minutes matches the handler's enrichAllTimeout — gives the geocoder + // enough headroom even for large batches. + if summary.Discovered > 0 { + go func() { + enrichCtx, cancel := context.WithTimeout(context.Background(), 45*time.Minute) + defer cancel() + if _, err := s.RunCrawlEnrichAll(enrichCtx); err != nil && !errors.Is(err, context.DeadlineExceeded) { + slog.WarnContext(context.Background(), "post-crawl enrichment failed", "error", err) + } + }() + } + summary.DurationMs = time.Since(summary.StartedAt).Milliseconds() slog.InfoContext(ctx, "crawl completed", "duration_ms", summary.DurationMs,