2021-01-18 18:15:42 -05:00
|
|
|
package cron
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
"github.com/ryanuber/columnize"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CommandList lists all scheduled cron tasks for a given app
|
|
|
|
|
func CommandList(appName string) error {
|
|
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 02:43:55 -04:00
|
|
|
entries, err := FetchCronEntries(appName)
|
2021-01-18 18:15:42 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output := []string{"ID | Schedule | Command"}
|
|
|
|
|
for _, entry := range entries {
|
|
|
|
|
output = append(output, fmt.Sprintf("%s | %s | %s", entry.ID, entry.Schedule, entry.Command))
|
|
|
|
|
}
|
|
|
|
|
result := columnize.SimpleFormat(output)
|
|
|
|
|
fmt.Println(result)
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandReport displays a cron report for one or more apps
|
2021-02-01 22:23:05 -05:00
|
|
|
func CommandReport(appName string, format string, infoFlag string) error {
|
2021-01-18 18:15:42 -05:00
|
|
|
if len(appName) == 0 {
|
|
|
|
|
apps, err := common.DokkuApps()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
for _, appName := range apps {
|
2021-02-01 22:23:05 -05:00
|
|
|
if err := ReportSingleApp(appName, format, infoFlag); err != nil {
|
2021-01-18 18:15:42 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 22:23:05 -05:00
|
|
|
return ReportSingleApp(appName, format, infoFlag)
|
2021-01-18 18:15:42 -05:00
|
|
|
}
|