diff --git a/backend/internal/runner/runner.go b/backend/internal/runner/runner.go index 66a4edf..56b2179 100644 --- a/backend/internal/runner/runner.go +++ b/backend/internal/runner/runner.go @@ -505,7 +505,11 @@ func (r *Runner) runScrapeTask(ctx context.Context, task domain.ScrapeTask) { log.Warn("runner: unknown task kind") } - if err := r.deps.Consumer.FinishScrapeTask(ctx, task.ID, result); err != nil { + // Use a fresh context for the final write so a cancelled task context doesn't + // prevent the result counters from being persisted to PocketBase. + finishCtx, finishCancel := context.WithTimeout(context.Background(), 15*time.Second) + defer finishCancel() + if err := r.deps.Consumer.FinishScrapeTask(finishCtx, task.ID, result); err != nil { log.Error("runner: FinishScrapeTask failed", "err", err) } @@ -551,7 +555,7 @@ func (r *Runner) runCatalogueTask(ctx context.Context, task domain.ScrapeTask, o TargetURL: entry.URL, } bookResult := o.RunBook(ctx, bookTask) - result.BooksFound += bookResult.BooksFound + 1 + result.BooksFound += bookResult.BooksFound result.ChaptersScraped += bookResult.ChaptersScraped result.ChaptersSkipped += bookResult.ChaptersSkipped result.Errors += bookResult.Errors