mirror of
https://github.com/dokku/dokku.git
synced 2026-08-29 01:59:07 +02:00
Cron containers were never reaped once they exceeded their active deadline, so a hung cron task ran indefinitely instead of being retired after 24 hours as documented. `cron:run` now also accepts a `--ttl-seconds` argument, matching the one `dokku run` already takes.
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
"github.com/dokku/dokku/plugins/cron"
|
|
|
|
flag "github.com/spf13/pflag"
|
|
)
|
|
|
|
// main entrypoint to all subcommands
|
|
func main() {
|
|
parts := strings.Split(os.Args[0], "/")
|
|
subcommand := parts[len(parts)-1]
|
|
|
|
var err error
|
|
switch subcommand {
|
|
case "list":
|
|
args := flag.NewFlagSet("cron:list", flag.ExitOnError)
|
|
global := args.Bool("global", false, "--global: set a global property")
|
|
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
if *global {
|
|
appName = "--global"
|
|
}
|
|
err = cron.CommandList(appName, *format)
|
|
case "report":
|
|
args := flag.NewFlagSet("cron:report", flag.ExitOnError)
|
|
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
|
reportArgs, flagErr := common.ParseReportArgs("cron", os.Args[2:])
|
|
if flagErr == nil {
|
|
args.Parse(reportArgs.OSArgs)
|
|
appName := args.Arg(0)
|
|
if reportArgs.IsGlobal {
|
|
appName = "--global"
|
|
}
|
|
err = cron.CommandReport(appName, *format, reportArgs.InfoFlag)
|
|
}
|
|
case "resume":
|
|
args := flag.NewFlagSet("cron:resume", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
cronID := args.Arg(1)
|
|
err = cron.CommandResume(appName, cronID)
|
|
case "run":
|
|
args := flag.NewFlagSet("cron:run", flag.ExitOnError)
|
|
detached := args.Bool("detach", false, "--detach: run the container in a detached mode")
|
|
ttlSeconds := args.Int64("ttl-seconds", cron.DefaultTTLSeconds, "--ttl-seconds: number of seconds the task may run before it is reaped")
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
cronID := args.Arg(1)
|
|
err = cron.CommandRun(appName, cronID, *detached, *ttlSeconds)
|
|
case "set":
|
|
args := flag.NewFlagSet("cron:set", flag.ExitOnError)
|
|
global := args.Bool("global", false, "--global: set a global property")
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
property := args.Arg(1)
|
|
value := args.Arg(2)
|
|
if *global {
|
|
appName = "--global"
|
|
property = args.Arg(0)
|
|
value = args.Arg(1)
|
|
}
|
|
err = cron.CommandSet(appName, property, value)
|
|
case "suspend":
|
|
args := flag.NewFlagSet("cron:suspend", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
cronID := args.Arg(1)
|
|
err = cron.CommandSuspend(appName, cronID)
|
|
default:
|
|
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
|
|
}
|
|
|
|
if err != nil {
|
|
common.LogFailWithError(err)
|
|
}
|
|
}
|