From 0719f8d28d0413bc080d42aac877a2ab5094a404 Mon Sep 17 00:00:00 2001 From: Silo Server Migration Date: Sat, 23 May 2026 21:36:41 -0400 Subject: [PATCH] Preserve collection apply progress until completion - Keep the last reported template bundle apply progress on success and failure - Poll admin collection apply jobs every 5 seconds in the UI --- internal/adminjob/runner.go | 10 +++++++--- web/src/hooks/queries/admin/collections.ts | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/adminjob/runner.go b/internal/adminjob/runner.go index e48499ed..197b06c2 100644 --- a/internal/adminjob/runner.go +++ b/internal/adminjob/runner.go @@ -403,7 +403,11 @@ func (r *Runner) executeTemplateBundleApply(job *models.AdminJob) { r.publishJobByID(ctx, notifications.TypeJobProgress, job.ID) } + lastCurrent := job.ProgressCurrent + lastTotal := job.ProgressTotal result, err := r.templateBundleApply.ExecuteTemplateBundleApply(ctx, req, func(current, total int, message string) { + lastCurrent = current + lastTotal = total if updateErr := r.repo.UpdateProgress(ctx, job.ID, current, total, message); updateErr != nil { slog.Warn("admin jobs: failed to update template bundle apply progress", "job_id", job.ID, @@ -420,15 +424,15 @@ func (r *Runner) executeTemplateBundleApply(job *models.AdminJob) { if ctx.Err() != nil { msg = fmt.Sprintf("timed out after %s: %s", templateBundleApplyTimeout, msg) } - r.failJob(job.ID, 0, 0, "Collection defaults apply failed", msg) + r.failJob(job.ID, lastCurrent, lastTotal, "Collection defaults apply failed", msg) return } if err := r.repo.Complete(ctx, job.ID, CompleteJobInput{ ResultPayload: result, Message: "Collection defaults applied", - ProgressCurrent: 0, - ProgressTotal: 0, + ProgressCurrent: lastCurrent, + ProgressTotal: lastTotal, ExpiresAt: time.Now().UTC().Add(r.retention), }); err != nil { slog.Warn("admin jobs: failed to complete template bundle apply", "job_id", job.ID, "error", err) diff --git a/web/src/hooks/queries/admin/collections.ts b/web/src/hooks/queries/admin/collections.ts index daaf287a..c25259e4 100644 --- a/web/src/hooks/queries/admin/collections.ts +++ b/web/src/hooks/queries/admin/collections.ts @@ -208,6 +208,8 @@ export function useTemplateBundleApplyJobs() { (data) => data.jobs ?? [], ), staleTime: 0, + refetchInterval: 5000, + refetchIntervalInBackground: true, }); }