1
0
mirror of https://github.com/offen/docker-volume-backup.git synced 2025-11-23 21:44:40 +02:00

Refactor handling of runtime configuration to prepare for reloading

This commit is contained in:
Frederik Ring
2024-02-13 19:21:57 +01:00
parent c4e480dcfd
commit 83fa0aae48
14 changed files with 665 additions and 520 deletions

View File

@@ -9,6 +9,9 @@ import (
"io"
"os"
"sync"
"time"
"github.com/robfig/cron/v3"
)
var noop = func() error { return nil }
@@ -79,3 +82,22 @@ func (c *concurrentSlice[T]) append(v T) {
func (c *concurrentSlice[T]) value() []T {
return c.val
}
// checkCronSchedule detects whether the given cron expression will actually
// ever be executed or not.
func checkCronSchedule(expression string) (ok bool) {
defer func() {
if err := recover(); err != nil {
ok = false
}
}()
sched, err := cron.ParseStandard(expression)
if err != nil {
ok = false
return
}
now := time.Now()
sched.Next(now) // panics when the cron would never run
ok = true
return
}