Skip to content

Modern Docker Management, Designed for Everyone

fix: restore image polling in additon to watcher bus

Kyle Mendell96907227c234
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.go
index 699a098dd..fc0ebec83 100644
--- a/backend/internal/bootstrap/jobs_bootstrap.go
+++ b/backend/internal/bootstrap/jobs_bootstrap.go
@@ -90,6 +90,7 @@ func registerDynamicJobs(appCtx context.Context, newScheduler *scheduler.JobSche
func setupSettingsCallbacks(lifecycleCtx context.Context, appServices *di.Services, appConfig *config.Config, newScheduler *scheduler.JobScheduler, jobs *di.Jobs) {
appServices.Settings.OnImagePollingSettingsChanged = func(_ context.Context) {
if jobs.ImageUpdateWatcher != nil {
+ jobs.ImageUpdateWatcher.RefreshSchedule()
jobs.ImageUpdateWatcher.Trigger()
}
if err := newScheduler.RescheduleJob(lifecycleCtx, jobs.AutoUpdate); err != nil {
diff --git a/backend/internal/di/wire_gen.go b/backend/internal/di/wire_gen.go
index 336f6bbcc..b550840e6 100644
--- a/backend/internal/di/wire_gen.go
+++ b/backend/internal/di/wire_gen.go
@@ -127,7 +127,7 @@ func InitializeJobs(ctx context.Context, cfg *config.Config, svcs *Services) *Jo
environmentService := svcs.Environment
dockerClientService := svcs.Docker
projectService := svcs.Project
- imageUpdateWatcher := scheduler.NewImageUpdateWatcher(imageUpdateService, settingsService, environmentService, dockerClientService, projectService)
+ imageUpdateWatcher := scheduler.NewImageUpdateWatcher(cfg, imageUpdateService, settingsService, environmentService, dockerClientService, projectService)
dockerClientRefreshJob := scheduler.NewDockerClientRefreshJob(dockerClientService, settingsService)
kvService := svcs.KV
analyticsJob := provideAnalyticsJobInternal(settingsService, kvService, cfg)
diff --git a/backend/internal/services/job_service.go b/backend/internal/services/job_service.go
index fda4ddbd7..b909a64d7 100644
--- a/backend/internal/services/job_service.go
+++ b/backend/internal/services/job_service.go
@@ -208,6 +208,19 @@ func (s *JobService) RescheduleJobsForSettingKeys(ctx context.Context, changedKe
continue
}
+ // Continuous bus watchers have no cron entry to reschedule; notify the
+ // watcher so it re-reads its poll schedule instead.
+ if jobMeta.IsContinuous {
+ if jobID == "image-polling" && s.settings != nil && s.settings.OnImagePollingSettingsChanged != nil {
+ notifyCtx := ctx //nolint:contextcheck // lifecycle context preferred so the watcher outlives the request
+ if s.lifecycleCtx != nil {
+ notifyCtx = s.lifecycleCtx
+ }
+ s.settings.OnImagePollingSettingsChanged(notifyCtx)
+ }
+ continue
+ }
+
job, ok := s.scheduler.GetJob(jobID)
if !ok {
rescheduleErrors = append(rescheduleErrors, fmt.Errorf("job %s not found in scheduler", jobID))
@@ -370,7 +383,9 @@ func (s *JobService) getRunnableJobInternal(jobID string) (schedulertypes.Job, e
}
func (s *JobService) getJobScheduleInternal(ctx context.Context, meta meta.JobMetadata) string {
- if meta.IsContinuous {
+ // Continuous jobs with a settings key (image-polling) are event-driven but
+ // also poll on that cron schedule, so surface the real expression.
+ if meta.IsContinuous && meta.SettingsKey == "" {
return "continuous"
}
diff --git a/backend/internal/services/job_service_test.go b/backend/internal/services/job_service_test.go
index b279199ec..aec63e20a 100644
--- a/backend/internal/services/job_service_test.go
+++ b/backend/internal/services/job_service_test.go
@@ -121,9 +121,9 @@ func TestJobService_ListJobs_ImageUpdateWatcherIsContinuousAndRespectsEnabled(t
watcher := findJobStatusByIDInternal(t, jobs.Jobs, "image-polling")
require.Equal(t, "Image Update Watcher", watcher.Name)
- require.Equal(t, "continuous", watcher.Schedule)
- require.Empty(t, watcher.SettingsKey)
- require.Nil(t, watcher.NextRun)
+ require.Equal(t, "0 0 * * * *", watcher.Schedule)
+ require.Equal(t, "pollingInterval", watcher.SettingsKey)
+ require.NotNil(t, watcher.NextRun)
require.True(t, watcher.IsContinuous)
require.True(t, watcher.CanRunManually)
require.False(t, watcher.Enabled)
diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.go
index b9ff2b381..8dabfd6a1 100644
--- a/backend/internal/services/settings_service.go
+++ b/backend/internal/services/settings_service.go
@@ -535,7 +535,7 @@ func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defa
valuesToUpdate = append(valuesToUpdate, models.SettingVariable{Key: key, Value: valueToSave})
switch key {
- case "pollingEnabled":
+ case "pollingEnabled", "pollingInterval":
changedPolling = true
case "autoUpdate", "autoUpdateInterval":
changedAutoUpdate = true
diff --git a/backend/pkg/scheduler/image_update_watcher.go b/backend/pkg/scheduler/image_update_watcher.go
index 797d9937e..17aa1dafc 100644
--- a/backend/pkg/scheduler/image_update_watcher.go
+++ b/backend/pkg/scheduler/image_update_watcher.go
@@ -9,6 +9,7 @@ import (
"sync/atomic"
"time"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/config"
"github.com/getarcaneapp/arcane/backend/v2/internal/services"
"github.com/getarcaneapp/arcane/types/v2/containerregistry"
"github.com/getarcaneapp/arcane/types/v2/imageupdate"
@@ -17,8 +18,9 @@ import (
)
const (
- imageUpdateWatcherDebounce = 2 * time.Second
- imageUpdateWatcherBackfillRetry = 5 * time.Second
+ imageUpdateWatcherDebounce = 2 * time.Second
+ imageUpdateWatcherBackfillRetry = 5 * time.Second
+ imageUpdateWatcherDefaultSchedule = "0 0 * * * *"
)
type imageUpdateScannerInternal interface {
@@ -31,6 +33,7 @@ type registryCredentialLoaderInternal interface {
type pollingSettingReaderInternal interface {
GetBoolSetting(ctx context.Context, key string, fallback bool) bool
+ GetStringSetting(ctx context.Context, key, defaultValue string) string
}
type dockerEventBusProviderInternal interface {
@@ -53,6 +56,8 @@ type ImageUpdateWatcher struct {
dockerService dockerEventBusProviderInternal
projectService projectImageRefsBackfillerInternal
triggerCh chan struct{}
+ scheduleRefreshCh chan struct{}
+ location *time.Location
debounce time.Duration
backfillRetry time.Duration
metadataReady chan struct{}
@@ -61,7 +66,11 @@ type ImageUpdateWatcher struct {
}
// NewImageUpdateWatcher constructs the image update watcher from the existing services.
-func NewImageUpdateWatcher(imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService, environmentService *services.EnvironmentService, dockerService *services.DockerClientService, projectService *services.ProjectService) *ImageUpdateWatcher {
+func NewImageUpdateWatcher(cfg *config.Config, imageUpdateService *services.ImageUpdateService, settingsService *services.SettingsService, environmentService *services.EnvironmentService, dockerService *services.DockerClientService, projectService *services.ProjectService) *ImageUpdateWatcher {
+ location := time.UTC
+ if cfg != nil {
+ location = cfg.GetLocation()
+ }
return &ImageUpdateWatcher{
imageUpdateService: imageUpdateService,
settingsService: settingsService,
@@ -69,6 +78,8 @@ func NewImageUpdateWatcher(imageUpdateService *services.ImageUpdateService, sett
dockerService: dockerService,
projectService: projectService,
triggerCh: make(chan struct{}, 1),
+ scheduleRefreshCh: make(chan struct{}, 1),
+ location: location,
debounce: imageUpdateWatcherDebounce,
backfillRetry: imageUpdateWatcherBackfillRetry,
metadataReady: make(chan struct{}),
@@ -108,6 +119,9 @@ func (w *ImageUpdateWatcher) Start(ctx context.Context) error {
}
}
})
+ listener.Go(func() {
+ w.runScheduledPollsInternal(ctx)
+ })
select {
case <-ctx.Done():
@@ -142,6 +156,17 @@ func (w *ImageUpdateWatcher) Trigger() {
}
}
+// RefreshSchedule wakes the scheduled-poll loop so it re-reads pollingInterval.
+func (w *ImageUpdateWatcher) RefreshSchedule() {
+ if w == nil || w.scheduleRefreshCh == nil {
+ return
+ }
+ select {
+ case w.scheduleRefreshCh <- struct{}{}:
+ default:
+ }
+}
+
// RunNow performs the same full-host image scan used by automatic watcher triggers.
func (w *ImageUpdateWatcher) RunNow(ctx context.Context) error {
if w == nil || w.settingsService == nil || w.imageUpdateService == nil || w.environmentService == nil || w.metadataReady == nil {
@@ -266,6 +291,47 @@ func (w *ImageUpdateWatcher) runTriggeredScansInternal(ctx context.Context) {
}
}
+// runScheduledPollsInternal periodically queues scans based on the
+// pollingInterval cron setting so registry-side updates are detected even when
+// no local Docker image events occur. Fires funnel through Trigger, sharing
+// the same debounce and single-flight path as event-driven scans.
+func (w *ImageUpdateWatcher) runScheduledPollsInternal(ctx context.Context) {
+ if w.scheduleRefreshCh == nil {
+ return
+ }
+ location := w.location
+ if location == nil {
+ location = time.UTC
+ }
+
+ for {
+ spec := imageUpdateWatcherDefaultSchedule
+ if w.settingsService != nil {
+ spec = w.settingsService.GetStringSetting(ctx, "pollingInterval", imageUpdateWatcherDefaultSchedule)
+ }
+ schedule, err := cronScheduleParser.Parse(spec)
+ if err != nil {
+ slog.WarnContext(ctx, "invalid pollingInterval cron expression; using default schedule", "pollingInterval", spec, "default", imageUpdateWatcherDefaultSchedule, "error", err)
+ schedule, err = cronScheduleParser.Parse(imageUpdateWatcherDefaultSchedule)
+ if err != nil {
+ slog.ErrorContext(ctx, "failed to parse default image polling schedule", "error", err)
+ return
+ }
+ }
+
+ timer := time.NewTimer(time.Until(schedule.Next(time.Now().In(location))))
+ select {
+ case <-ctx.Done():
+ timer.Stop()
+ return
+ case <-w.scheduleRefreshCh:
+ timer.Stop()
+ case <-timer.C:
+ w.Trigger()
+ }
+ }
+}
+
func (w *ImageUpdateWatcher) waitForDebounceInternal(ctx context.Context) bool {
timer := time.NewTimer(w.debounce)
defer timer.Stop()
diff --git a/backend/pkg/scheduler/image_update_watcher_test.go b/backend/pkg/scheduler/image_update_watcher_test.go
index 1837c3a2f..6df45a569 100644
--- a/backend/pkg/scheduler/image_update_watcher_test.go
+++ b/backend/pkg/scheduler/image_update_watcher_test.go
@@ -75,8 +75,9 @@ func (s *imageUpdateScannerFakeInternal) maxActiveInternal() int {
}
type pollingSettingReaderFakeInternal struct {
- mu sync.RWMutex
- enabled bool
+ mu sync.RWMutex
+ enabled bool
+ schedule string
}
func (s *pollingSettingReaderFakeInternal) GetBoolSetting(context.Context, string, bool) bool {
@@ -85,6 +86,15 @@ func (s *pollingSettingReaderFakeInternal) GetBoolSetting(context.Context, strin
return s.enabled
}
+func (s *pollingSettingReaderFakeInternal) GetStringSetting(_ context.Context, _ string, defaultValue string) string {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+ if s.schedule == "" {
+ return defaultValue
+ }
+ return s.schedule
+}
+
func (s *pollingSettingReaderFakeInternal) setEnabledInternal(enabled bool) {
s.mu.Lock()
s.enabled = enabled
@@ -166,6 +176,8 @@ func newImageUpdateWatcherForTestInternal(scanner imageUpdateScannerInternal, se
dockerService: dockerEventBusProviderFakeInternal{eventBus: eventBus},
projectService: backfiller,
triggerCh: make(chan struct{}, 1),
+ scheduleRefreshCh: make(chan struct{}, 1),
+ location: time.UTC,
debounce: 10 * time.Millisecond,
backfillRetry: 10 * time.Millisecond,
metadataReady: make(chan struct{}),
@@ -433,6 +445,16 @@ func TestImageUpdateWatcher_CancellationStopsBackfillWithoutScanning(t *testing.
require.Zero(t, scanner.countInternal())
}
+func TestImageUpdateWatcher_ScheduledPollTriggersScanWithoutEvents(t *testing.T) {
+ scanner := &imageUpdateScannerFakeInternal{}
+ settings := &pollingSettingReaderFakeInternal{enabled: true, schedule: "* * * * * *"}
+ watcher := newImageUpdateWatcherForTestInternal(scanner, settings, bus.NewDockerEventBus(), nil)
+ startImageUpdateWatcherForTestInternal(t, watcher)
+
+ require.Eventually(t, func() bool { return scanner.countInternal() == 1 }, time.Second, 5*time.Millisecond)
+ require.Eventually(t, func() bool { return scanner.countInternal() >= 2 }, 3*time.Second, 10*time.Millisecond)
+}
+
func TestImageUpdateWatcher_RunNowWaitsForMetadataReadiness(t *testing.T) {
scanner := &imageUpdateScannerFakeInternal{}
settings := &pollingSettingReaderFakeInternal{enabled: true}
diff --git a/backend/pkg/scheduler/job_schedule_integration_test.go b/backend/pkg/scheduler/job_schedule_integration_test.go
index a6e1ef689..04ba77d3e 100644
--- a/backend/pkg/scheduler/job_schedule_integration_test.go
+++ b/backend/pkg/scheduler/job_schedule_integration_test.go
@@ -52,10 +52,10 @@ func TestDeprecatedImagePollingSchedulePersistsWithoutRuntimeJob(t *testing.T) {
jobs, err := jobService.ListJobs(ctx)
require.NoError(t, err)
imagePollingStatus := findJobStatusInternal(t, jobs, "image-polling")
- require.Equal(t, "continuous", imagePollingStatus.Schedule)
- require.Nil(t, imagePollingStatus.NextRun)
+ require.Equal(t, requestedSchedule, imagePollingStatus.Schedule)
+ require.NotNil(t, imagePollingStatus.NextRun)
require.True(t, imagePollingStatus.IsContinuous)
- require.Empty(t, imagePollingStatus.SettingsKey)
+ require.Equal(t, "pollingInterval", imagePollingStatus.SettingsKey)
cancelLifecycle()
waitForSchedulerStopInternal(jobScheduler)
@@ -80,7 +80,7 @@ func TestDeprecatedImagePollingSchedulePersistsWithoutRuntimeJob(t *testing.T) {
restartedJobs, err := restartJobService.ListJobs(ctx)
require.NoError(t, err)
- require.Equal(t, "continuous", findJobStatusInternal(t, restartedJobs, "image-polling").Schedule)
+ require.Equal(t, requestedSchedule, findJobStatusInternal(t, restartedJobs, "image-polling").Schedule)
require.NoError(t, restartSettingsService.SetBoolSetting(ctx, "pollingEnabled", false))
disabledSchedule := "0 0 9 * * *"
@@ -95,8 +95,7 @@ func TestDeprecatedImagePollingSchedulePersistsWithoutRuntimeJob(t *testing.T) {
require.NoError(t, err)
disabledStatus := findJobStatusInternal(t, disabledJobs, "image-polling")
require.False(t, disabledStatus.Enabled)
- require.Nil(t, disabledStatus.NextRun)
- require.Equal(t, "continuous", disabledStatus.Schedule)
+ require.Equal(t, disabledSchedule, disabledStatus.Schedule)
}
func openJobScheduleTestDatabaseInternal(t *testing.T, ctx context.Context, databasePath string) (*database.DB, *services.SettingsService) {
diff --git a/backend/pkg/scheduler/scheduler.go b/backend/pkg/scheduler/scheduler.go
index 0bf06a772..1cc282c7c 100644
--- a/backend/pkg/scheduler/scheduler.go
+++ b/backend/pkg/scheduler/scheduler.go
@@ -11,6 +11,11 @@ import (
"github.com/robfig/cron/v3"
)
+// cronScheduleParser is the shared parser for all cron settings: six fields
+// with seconds, plus @-descriptors. The image update watcher parses its poll
+// schedule with the same spec so Jobs-UI cron values behave identically.
+var cronScheduleParser = cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor)
+
type JobScheduler struct {
// mu guards jobs, jobsByID, entryIDs and schedules. It is held across the cron
// add/remove calls (which are themselves quick and never block on job
@@ -36,7 +41,7 @@ func NewJobScheduler(ctx context.Context, location *time.Location) *JobScheduler
if location == nil {
location = time.UTC
}
- parser := cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor)
+ parser := cronScheduleParser
slog.InfoContext(ctx, "Initializing job scheduler", "timezone", location.String())
return &JobScheduler{
cron: cron.New(cron.WithParser(parser), cron.WithLocation(location)),
diff --git a/frontend/src/lib/components/job-card/job-card.svelte b/frontend/src/lib/components/job-card/job-card.svelte
index 24e2a65ce..3ce16b5ca 100644
--- a/frontend/src/lib/components/job-card/job-card.svelte
+++ b/frontend/src/lib/components/job-card/job-card.svelte
@@ -79,7 +79,7 @@
{#if headerAccessory}
{@render headerAccessory()}
{/if}
- {#if isEnabled && !job.isContinuous && job.settingsKey}
+ {#if isEnabled && job.settingsKey}
<Button
variant="ghost"
size="icon"
@@ -112,7 +112,7 @@
<Card.Content class="space-y-2 px-4 pt-0 pb-4">
{#if isEnabled}
<div class="grid gap-2 text-xs text-muted-foreground">
- {#if !job.isContinuous}
+ {#if !job.isContinuous || job.settingsKey}
<div class="flex items-center gap-2">
<ClockIcon class="h-3.5 w-3.5" />
<span>{m.jobs_schedule()}:</span>
diff --git a/types/jobschedule/jobschedule.go b/types/jobschedule/jobschedule.go
index a6a196eb0..5889cfcf1 100644
--- a/types/jobschedule/jobschedule.go
+++ b/types/jobschedule/jobschedule.go
@@ -12,7 +12,7 @@ type Config struct {
ExpiredSessionsCleanupInterval string `json:"expiredSessionsCleanupInterval"`
AutoUpdateInterval string `json:"autoUpdateInterval"`
DockerClientRefreshInterval string `json:"dockerClientRefreshInterval"`
- PollingInterval string `json:"pollingInterval"` // Deprecated: image update checks are event-driven.
+ PollingInterval string `json:"pollingInterval"`
ScheduledPruneInterval string `json:"scheduledPruneInterval"`
VulnerabilityScanInterval string `json:"vulnerabilityScanInterval"`
AutoHealInterval string `json:"autoHealInterval"`
@@ -27,7 +27,7 @@ type Update struct {
ExpiredSessionsCleanupInterval *string `json:"expiredSessionsCleanupInterval,omitempty"`
AutoUpdateInterval *string `json:"autoUpdateInterval,omitempty"`
DockerClientRefreshInterval *string `json:"dockerClientRefreshInterval,omitempty"`
- PollingInterval *string `json:"pollingInterval,omitempty"` // Deprecated: accepted and persisted for compatibility, but ignored.
+ PollingInterval *string `json:"pollingInterval,omitempty"`
ScheduledPruneInterval *string `json:"scheduledPruneInterval,omitempty"`
VulnerabilityScanInterval *string `json:"vulnerabilityScanInterval,omitempty"`
AutoHealInterval *string `json:"autoHealInterval,omitempty"`
diff --git a/types/meta/job_metadata.go b/types/meta/job_metadata.go
index 014b5b4b4..0e79539d8 100644
--- a/types/meta/job_metadata.go
+++ b/types/meta/job_metadata.go
@@ -113,9 +113,9 @@ var jobMetadataRegistry = map[string]JobMetadata{
"image-polling": {
ID: "image-polling",
Name: "Image Update Watcher",
- Description: "Checks container registries after Docker image changes",
+ Description: "Checks container registries on a schedule and after Docker image changes",
Category: "updates",
- SettingsKey: "",
+ SettingsKey: "pollingInterval",
EnabledKey: "pollingEnabled",
ManagerOnly: false,
IsContinuous: true,