Pre-loading batches into list

This commit is contained in:
IamTheFij 2018-08-01 08:59:52 -07:00
parent 2318a12ff2
commit aa6da671ea
1 changed files with 8 additions and 7 deletions

15
main.go
View File

@ -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()