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/docker/docker/client"
"github.com/robfig/cron" "github.com/robfig/cron"
"golang.org/x/net/context" "golang.org/x/net/context"
"io"
"log"
"os"
"strings" "strings"
"time" "time"
) )
@ -40,15 +37,12 @@ func main() {
panic(err) panic(err)
} }
c := cron.New()
jobs := []ContainerStartJob{} jobs := []ContainerStartJob{}
for _, container := range containers { for _, container := range containers {
if val, ok := container.Labels["cron.schedule"]; ok { if val, ok := container.Labels["cron.schedule"]; ok {
jobName := strings.Join(container.Names, "/") jobName := strings.Join(container.Names, "/")
fmt.Println("Scheduling ", jobName, "(", val, ")") jobs = append(jobs, ContainerStartJob{
c.AddJob(val, ContainerStartJob{
Schedule: val, Schedule: val,
Client: cli, Client: cli,
ContainerID: container.ID, 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 // Start the cron job threads
c.Start() c.Start()