Skip to content

Commit

Permalink
add -retry-delay option
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Oct 19, 2023
1 parent 156bc99 commit 85b027d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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. "+
Expand Down Expand Up @@ -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--

Expand Down

0 comments on commit 85b027d

Please sign in to comment.