这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 68 additions & 28 deletions plugins/cron/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

appjson "github.com/dokku/dokku/plugins/app-json"
"github.com/dokku/dokku/plugins/common"
"golang.org/x/sync/errgroup"

base36 "github.com/multiformats/go-base36"
cronparser "github.com/robfig/cron/v3"
Expand Down Expand Up @@ -98,44 +99,83 @@ func deleteCrontab() error {
return nil
}

func writeCronEntries() error {
func generateCronEntries() ([]templateCommand, error) {
apps, _ := common.UnfilteredDokkuApps()
commands := []templateCommand{}

g := new(errgroup.Group)
results := make(chan []templateCommand, len(apps)+1)
for _, appName := range apps {
scheduler := common.GetAppScheduler(appName)
if scheduler != "docker-local" {
continue
}
appName := appName
g.Go(func() error {
scheduler := common.GetAppScheduler(appName)
if scheduler != "docker-local" {
results <- []templateCommand{}
return nil
}

c, err := fetchCronEntries(appName)
if err != nil {
results <- []templateCommand{}
return err
}

results <- c
return nil
})
}

c, err := fetchCronEntries(appName)
if err != nil {
return err
g.Go(func() error {
commands := []templateCommand{}
b, _ := common.PlugnTriggerOutput("cron-entries", "docker-local")
for _, line := range strings.Split(strings.TrimSpace(string(b[:])), "\n") {
if strings.TrimSpace(line) == "" {
results <- []templateCommand{}
return nil
}

parts := strings.Split(line, ";")
if len(parts) != 2 && len(parts) != 3 {
results <- []templateCommand{}
return fmt.Errorf("Invalid injected cron task: %v", line)
}

id := base36.EncodeToStringLc([]byte(strings.Join(parts, ";;;")))
command := templateCommand{
ID: id,
Schedule: parts[0],
AltCommand: parts[1],
}
if len(parts) == 3 {
command.LogFile = parts[2]
}
commands = append(commands, command)
}
results <- commands
return nil
})

commands = append(commands, c...)
err := g.Wait()
close(results)

commands := []templateCommand{}
if err != nil {
return commands, err
}

b, _ := common.PlugnTriggerOutput("cron-entries", "docker-local")
for _, line := range strings.Split(strings.TrimSpace(string(b[:])), "\n") {
if strings.TrimSpace(line) == "" {
continue
for result := range results {
c := result
if len(c) > 0 {
commands = append(commands, c...)
}
}

parts := strings.Split(line, ";")
if len(parts) != 2 && len(parts) != 3 {
return fmt.Errorf("Invalid injected cron task: %v", line)
}
return commands, nil
}

id := base36.EncodeToStringLc([]byte(strings.Join(parts, ";;;")))
command := templateCommand{
ID: id,
Schedule: parts[0],
AltCommand: parts[1],
}
if len(parts) == 3 {
command.LogFile = parts[2]
}
commands = append(commands, command)
func writeCronEntries() error {
commands, err := generateCronEntries()
if err != nil {
return err
}

if len(commands) == 0 {
Expand Down