From aa6da671eac34a78fc95164890b585973f6ba5df Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Wed, 1 Aug 2018 08:59:52 -0700 Subject: [PATCH] Pre-loading batches into list --- main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index d78a2ac..134a479 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,6 @@ import ( "github.com/docker/docker/client" "github.com/robfig/cron" "golang.org/x/net/context" - "io" - "log" - "os" "strings" "time" ) @@ -40,15 +37,12 @@ func main() { panic(err) } - c := cron.New() - jobs := []ContainerStartJob{} for _, container := range containers { if val, ok := container.Labels["cron.schedule"]; ok { jobName := strings.Join(container.Names, "/") - fmt.Println("Scheduling ", jobName, "(", val, ")") - c.AddJob(val, ContainerStartJob{ + jobs = append(jobs, ContainerStartJob{ Schedule: val, Client: cli, ContainerID: container.ID, @@ -58,6 +52,13 @@ func main() { } } + c := cron.New() + + for _, job := range jobs { + fmt.Println("Scheduling ", job.Name, "(", job.Schedule, ")") + c.AddJob(job.Schedule, job) + } + // Start the cron job threads c.Start()