Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: auto update job not running
Kyle Mendell41d8a6596c83
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.goindex 2dc4b404d..84db50858 100644--- a/backend/internal/bootstrap/jobs_bootstrap.go+++ b/backend/internal/bootstrap/jobs_bootstrap.go@@ -92,6 +92,7 @@ func setupSettingsCallbacks(appServices *Services, appConfig *config.Config, ima}}appServices.Settings.OnAutoUpdateSettingsChanged = func(ctx context.Context) {+ slog.DebugContext(ctx, "AutoUpdateSettingsChanged callback triggered")if err := autoUpdateJob.Reschedule(ctx); err != nil {slog.WarnContext(ctx, "Failed to reschedule auto-update job", "error", err)}diff --git a/backend/internal/job/job.go b/backend/internal/job/job.goindex e532e0442..aaa151b37 100644--- a/backend/internal/job/job.go+++ b/backend/internal/job/job.go@@ -26,6 +26,9 @@ func (s *Scheduler) Run(ctx context.Context) error {slog.InfoContext(ctx, "Starting job scheduler")s.scheduler.Start() // Start the scheduler, non-blocking+ time.Sleep(100 * time.Millisecond)+ s.LogJobStatus(ctx)+// Wait for the context to be done (e.g., application shutdown)<-ctx.Done()@@ -48,38 +51,39 @@ func (s *Scheduler) RegisterJob(runImmediately bool,) error {jobOptions := []gocron.JobOption{- gocron.WithContext(ctx),gocron.WithName(name),gocron.WithEventListeners(gocron.BeforeJobRuns(func(jobID uuid.UUID, jobName string) {- slog.InfoContext(ctx, "Job starting", "name", name, "id", jobID.String())+ slog.Info("Job starting", "name", name, "id", jobID.String())}),gocron.AfterJobRuns(func(jobID uuid.UUID, jobName string) {- slog.InfoContext(ctx, "Job finished successfully", "name", name, "id", jobID.String())+ slog.Info("Job finished successfully", "name", name, "id", jobID.String())}),gocron.AfterJobRunsWithError(func(jobID uuid.UUID, jobName string, err error) {- slog.ErrorContext(ctx, "Job failed", "name", name, "id", jobID.String(), "error", err)+ slog.Error("Job failed", "name", name, "id", jobID.String(), "error", err)}),),}task := gocron.NewTask(func() {if err := taskFunc(ctx); err != nil {- slog.ErrorContext(ctx, "Error executing task function", "name", name, "error", err)+ slog.Error("Error executing task function", "name", name, "error", err)}})+ var job gocron.Jobvar err errorif runImmediately {- _, err = s.scheduler.NewJob(definition, task, append(jobOptions, gocron.WithStartAt(gocron.WithStartImmediately()))...)+ job, err = s.scheduler.NewJob(definition, task, append(jobOptions, gocron.WithStartAt(gocron.WithStartImmediately()))...)} else {- _, err = s.scheduler.NewJob(definition, task, jobOptions...)+ job, err = s.scheduler.NewJob(definition, task, jobOptions...)}if err != nil {return fmt.Errorf("failed to register job %q: %w", name, err)}- slog.InfoContext(ctx, "Job registered successfully", "name", name)+ nextRun, _ := job.NextRun()+ slog.InfoContext(ctx, "Job registered successfully", "name", name, "nextRun", nextRun.Format(time.RFC3339), "runImmediately", runImmediately)return nil}@@ -98,7 +102,21 @@ func (s *Scheduler) RescheduleDurationJobByName(taskFunc func(ctx context.Context) error,runImmediately bool,) error {+ slog.DebugContext(ctx, "Rescheduling job", "name", name, "interval", interval.String())s.RemoveJobByName(name)definition := gocron.DurationJob(interval)return s.RegisterJob(ctx, name, definition, taskFunc, runImmediately)}++func (s *Scheduler) LogJobStatus(ctx context.Context) {+ jobs := s.scheduler.Jobs()+ slog.InfoContext(ctx, "Active jobs in scheduler", "count", len(jobs))+ for _, j := range jobs {+ nextRun, err := j.NextRun()+ if err != nil {+ slog.WarnContext(ctx, "Could not get next run for job", "name", j.Name(), "error", err)+ continue+ }+ slog.InfoContext(ctx, "Job status", "name", j.Name(), "id", j.ID().String(), "nextRun", nextRun.Format(time.RFC3339))+ }+}diff --git a/backend/internal/services/updater_service.go b/backend/internal/services/updater_service.goindex 3661b98b5..81ac43318 100644--- a/backend/internal/services/updater_service.go+++ b/backend/internal/services/updater_service.go@@ -187,12 +187,18 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*updatehost, repo, tag := s.parseNormalizedRef(normNew)authHeader, _, _, _ := arcRegistry.ResolveAuthHeaderForRepository(ctx, host, repo, tag, enabledRegs)check := digestChecker.CheckImageNeedsUpdate(ctx, normNew, authHeader)+ skipPull := false+if check.CheckedViaAPI && check.Error == nil && !check.NeedsUpdate {item.Status = "skipped"item.Error = "image already up to date"out.Skipped++- out.Items = append(out.Items, item)- _ = s.recordRun(ctx, item)+ // We skip checking for pull, but we still proceed to container update checks+ // treating this as "successful" for the pipeline, but invalidating oldIDs+ // because they represent the *current* image, not a stale one.+ plans[i].pulled = true+ plans[i].oldIDs = nil+ skipPull = trues.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{"phase": "image_pull",@@ -204,34 +210,35 @@ func (s *UpdaterService) ApplyPending(ctx context.Context, dryRun bool) (*update"checkedViaApi": true,"error": item.Error,})- continue}- if err := s.imageService.PullImage(ctx, p.newRef, io.Discard, systemUser, nil); err != nil {- item.Status = "failed"- item.Error = err.Error()- out.Failed++- } else {- item.Status = "updated"- item.UpdateApplied = true- out.Updated++- plans[i].pulled = true- for _, id := range p.oldIDs {- if id != "" {- oldIDSet[id] = struct{}{}+ if !skipPull {+ if err := s.imageService.PullImage(ctx, p.newRef, io.Discard, systemUser, nil); err != nil {+ item.Status = "failed"+ item.Error = err.Error()+ out.Failed+++ } else {+ item.Status = "updated"+ item.UpdateApplied = true+ out.Updated+++ plans[i].pulled = true+ for _, id := range p.oldIDs {+ if id != "" {+ oldIDSet[id] = struct{}{}+ }}}+ s.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{+ "phase": "image_pull",+ "imageOld": p.oldRef,+ "imageNew": p.newRef,+ "status": item.Status,+ "error": item.Error,+ })}+out.Items = append(out.Items, item)_ = s.recordRun(ctx, item)-- s.logAutoUpdate(ctx, s.severityFromStatus(item.Status), models.JSON{- "phase": "image_pull",- "imageOld": p.oldRef,- "imageNew": p.newRef,- "status": item.Status,- "error": item.Error,- })}// Build maps for fast matching later (only for successfully pulled updates)@@ -996,6 +1003,9 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldIDmarkedForRestart := map[string]bool{}containersWithDeps := make([]arcaneupdater.ContainerWithDeps, 0, len(list))+ // Cache resolved IDs for newRefs to avoid repeated API calls+ targetImageIDs := map[string][]string{}+for _, c := range list {inspect, err := dcli.ContainerInspect(ctx, c.ID)if err != nil {@@ -1040,6 +1050,25 @@ func (s *UpdaterService) restartContainersUsingOldIDs(ctx context.Context, oldID}}+ if newRef != "" {+ // Check if container is already on the target image+ tids, cached := targetImageIDs[newRef]+ if !cached {+ tids, _ = s.resolveLocalImageIDsForRef(ctx, newRef)+ targetImageIDs[newRef] = tids+ }++ for _, tid := range tids {+ if tid == inspect.Image {+ // Already on target image+ slog.InfoContext(ctx, "restartContainersUsingOldIDs: container already on target image; skipping restart",+ "containerId", c.ID, "containerName", dep.Name, "imageID", inspect.Image, "newRef", newRef)+ newRef = ""+ break+ }+ }+ }+p := &restartPlan{cnt: c, inspect: inspect, newRef: newRef, match: match, explicit: newRef != ""}plansByName[dep.Name] = pif p.explicit {