Allow to disable updates schedule
This commit is contained in:
@@ -40,10 +40,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
module *modules.Module
|
module *modules.Module
|
||||||
registry *updater.ResourceRegistry
|
registry *updater.ResourceRegistry
|
||||||
updateTask *modules.Task
|
updateTask *modules.Task
|
||||||
updateASAP = abool.New()
|
updateASAP = abool.New()
|
||||||
|
disableTaskSchedule bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -111,7 +112,14 @@ func start() error {
|
|||||||
// start updater task
|
// start updater task
|
||||||
updateTask = module.NewTask("updater", func(ctx context.Context, task *modules.Task) error {
|
updateTask = module.NewTask("updater", func(ctx context.Context, task *modules.Task) error {
|
||||||
return checkForUpdates(ctx)
|
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() {
|
if updateASAP.IsSet() {
|
||||||
updateTask.StartASAP()
|
updateTask.StartASAP()
|
||||||
@@ -136,6 +144,19 @@ func TriggerUpdate() error {
|
|||||||
return nil
|
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 {
|
func checkForUpdates(ctx context.Context) error {
|
||||||
err := registry.DownloadUpdates(ctx)
|
err := registry.DownloadUpdates(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user