3
0
mirror of https://kolaente.dev/konrad/docker-db-backup.git synced 2026-01-10 02:50:08 +01:00

feat: replace interval with a proper cron schedule

This commit is contained in:
kolaente
2021-12-30 12:57:58 +01:00
parent 7b8e1d187c
commit 9cecce4f2d
5 changed files with 20 additions and 19 deletions

12
main.go
View File

@@ -1,8 +1,8 @@
package main
import (
"github.com/robfig/cron/v3"
"log"
"time"
)
func main() {
@@ -11,7 +11,8 @@ func main() {
log.Fatalf("Could not create client: %s", err)
}
for {
cr := cron.New()
_, err = cr.AddFunc(config.Schedule, func() {
updateFullBackupPath()
containers, err := getContainers(c)
@@ -32,8 +33,9 @@ func main() {
}
log.Println("Done.")
log.Printf("Sleeping for %s\n", config.Interval)
time.Sleep(config.Interval)
})
if err != nil {
log.Fatalf("Could not create cron job: %s\n", err)
}
cr.Start()
}