diff --git a/README.md b/README.md index a247076..48aa51c 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,8 @@ If you plan to use the `RUNNER_OUTFD_PID` and `RUNNER_OUTFD_STD[OUT|ERR]` variab - Can also be set by the `RUNNER_LOG_DIR` environment variable; this flag overrides the environment variable. - `-print-if-match value`: Print/mail output if the given (**case-sensitive**) string appears in the program's output, even if it was a healthy exit. May be specified multiple times. - `-print-if-not-match value`: Print/mail output if the given (**case-sensitive**) string does not appear in the program's output, even if it was a healthy exit. May be specified multiple times. -- `-retries int`: If the command fails, retry it this many times. +- `-retries int`: If the command fails, retry it this many times. (default: `0`) +- `-retry-delay int`: If the command fails, wait this many seconds before retrying. (default: `0`) - `-version`: Print version and exit. - `-work-dir string`: Set the working directory for the program. diff --git a/runner.go b/runner.go index aa32291..a09ea1e 100644 --- a/runner.go +++ b/runner.go @@ -84,6 +84,7 @@ func main() { fmt.Sprintf("Can also be set by the %s environment variable; this flag overrides the environment variable.", LogDirEnvVar)) workDir := flag.String("work-dir", "", "Set the working directory for the program.") retries := flag.Int("retries", 0, "If the command fails, retry it this many times.") + retryDelayInt := flag.Int("retry-delay", 0, "If the command fails, wait this many seconds before retrying.") asUser := flag.String("user", "", "Run the program as the given user. Ignored on Windows. "+ "(If provided, runner must be run as root or with CAP_SETUID and CAP_SETGID.)") asUID := flag.Int("uid", -1, "Run the program as the given UID. Ignored on Windows. "+ @@ -229,7 +230,10 @@ func main() { for triesRemaining > 0 { if *retries > 0 && triesRemaining != 1+*retries { - programOutput = programOutput + "\n- Retrying -\n\n" + if *retryDelayInt > 0 { + time.Sleep(time.Duration(*retryDelayInt) * time.Second) + } + programOutput = programOutput + fmt.Sprintf("\n- Retrying after %d seconds -\n\n", *retryDelayInt) } triesRemaining--