Skip to content

Commit

Permalink
Add an option to display worker identifier in result output (#27)
Browse files Browse the repository at this point in the history
* Add an option to display worker identifier in result output

* Fix format
  • Loading branch information
dvnscr authored Feb 1, 2024
1 parent a7347c9 commit 2bbe7df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type configurationStruct struct {
flagProfile string
flagCPUProfile string
flagMemProfile string
// append worker hostname to result output
workerNameInResult bool
}

// setDefaultValues sets reasonable defaults
Expand Down Expand Up @@ -102,6 +104,7 @@ func (config *configurationStruct) setDefaultValues() {
config.internalNegate = true
config.internalCheckDummy = true
config.internalCheckNscWeb = true
config.workerNameInResult = false
filename, err := os.Executable()
if err == nil {
config.p1File = path.Join(path.Dir(filename), "mod_gearman_worker_epn.pl")
Expand Down Expand Up @@ -169,6 +172,7 @@ func (config *configurationStruct) dump() {
logger.Debugf("internal_negate %v\n", config.internalNegate)
logger.Debugf("internal_check_dummy %v\n", config.internalCheckDummy)
logger.Debugf("internal_check_nsc_web %v\n", config.internalCheckNscWeb)
logger.Debugf("worker_name_in_result %v\n", config.workerNameInResult)
if config.binary == "send_gearman" {
logger.Debugf("returncode %d\n", config.returnCode)
logger.Debugf("message %s\n", config.message)
Expand Down Expand Up @@ -330,6 +334,8 @@ func (config *configurationStruct) parseConfigItem(raw string) error {
config.internalCheckDummy = getBool(value)
case "internal_check_nsc_web":
config.internalCheckNscWeb = getBool(value)
case "worker_name_in_result":
config.workerNameInResult = getBool(value)
case "fork_on_exec":
// skip legacy option
case "workaround_rc_25":
Expand Down
3 changes: 3 additions & 0 deletions readAndExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func execEPN(result *answer, cmd *command, received *receivedStruct) {

func fixReturnCodes(result *answer, config *configurationStruct, state *os.ProcessState) {
if result.returnCode >= 0 && result.returnCode <= 3 {
if config.workerNameInResult {
result.output = fmt.Sprintf("%s (worker: %s)", result.output, config.identifier)
}
return
}
if result.returnCode == exitCodeNotExecutable {
Expand Down
4 changes: 4 additions & 0 deletions worker.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ use_perl_cache=on
#internal_check_dummy = 1


# Show worker identifier in result output
#worker_name_in_result=no


# Prometheus
# export prometheus metrics
#prometheus_server=127.0.0.1:9050
Expand Down

0 comments on commit 2bbe7df

Please sign in to comment.