-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flags to customize ping type decisions
Context: Healthchecks added a "log" ping type to cater to use cases where a periodic command is likely to exit with failure status but expected to eventually succeed in future instantiations. healthchecks/healthchecks#525 (comment) Problems: - "log" ping type is not supported. - Let the user decide ping type to be sent for success, nonzero exit, or execution failure (e.g. command not found, no permission, system ran out pids, ...) Changes: - Introduce three new flags: + -on-success: ping type type to send when command exits successfully. defaults to "success". + -on-nonzero-exit: ping type to send when command exits with nonzero code. defaults to "exit-code". + -on-exec-fail: ping type to send when runitor cannot execute the command. defaults to "fail" + valid values for these flags are: "exit-code", "success", "fail", "log". - Addresses lack of "log" ping type support and use case in #65.
- Loading branch information
Showing
5 changed files
with
196 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// PingType is an enumerator type for PingType* constants. | ||
type PingType int | ||
|
||
//go:generate enumer -type PingType -trimprefix=PingType -transform=kebab | ||
const ( | ||
PingTypeExitCode PingType = iota | ||
PingTypeSuccess | ||
PingTypeFail | ||
PingTypeLog | ||
) | ||
|
||
func pingTypeFlag(name string, dflt PingType, usage string) *PingType { | ||
p := new(PingType) | ||
*p = dflt | ||
|
||
opts := fmt.Sprintf("%s (default %s)", pingTypeOpts("|"), dflt) | ||
usage = usage + " (" + opts + ")" | ||
flag.Func(name, usage, func(s string) (err error) { | ||
*p, err = PingTypeString(s) | ||
if err != nil { | ||
err = fmt.Errorf("recognized options: %s", opts) | ||
} | ||
return err | ||
}) | ||
|
||
return p | ||
} | ||
|
||
func pingTypeOpts(sep string) string { | ||
var b strings.Builder | ||
for _, v := range PingTypeValues() { | ||
if b.Len() > 0 { | ||
b.WriteString(sep) | ||
} | ||
b.WriteString(v.String()) | ||
} | ||
|
||
return b.String() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters