Allow to disable updates schedule

This commit is contained in:
ppacher
2020-04-06 12:35:29 +02:00
parent 5067576260
commit 30800f7383

View File

@@ -40,10 +40,11 @@ const (
)
var (
module *modules.Module
registry *updater.ResourceRegistry
updateTask *modules.Task
updateASAP = abool.New()
module *modules.Module
registry *updater.ResourceRegistry
updateTask *modules.Task
updateASAP = abool.New()
disableTaskSchedule bool
)
func init() {
@@ -111,7 +112,14 @@ func start() error {
// start updater task
updateTask = module.NewTask("updater", func(ctx context.Context, task *modules.Task) error {
return checkForUpdates(ctx)
}).Repeat(24 * time.Hour).MaxDelay(1 * time.Hour).Schedule(time.Now().Add(10 * time.Second))
})
if !disableTaskSchedule {
updateTask.
Repeat(24 * time.Hour).
MaxDelay(1 * time.Hour).
Schedule(time.Now().Add(10 * time.Second))
}
if updateASAP.IsSet() {
updateTask.StartASAP()
@@ -136,6 +144,19 @@ func TriggerUpdate() error {
return nil
}
// DisableUpdateSchedule disables the update schedule.
// If called, updates are only checked when TriggerUpdate()
// is called.
func DisableUpdateSchedule() error {
if module.Online() {
return fmt.Errorf("module already online")
}
disableTaskSchedule = true
return nil
}
func checkForUpdates(ctx context.Context) error {
err := registry.DownloadUpdates(ctx)
if err != nil {