Skip to content

Commit

Permalink
fix timeout bug
Browse files Browse the repository at this point in the history
  • Loading branch information
taigrr committed Mar 11, 2024
1 parent 9d19053 commit b08e2e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 2 additions & 3 deletions cmd/grlx/ingredients/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func FRun(target string, command types.CmdRun) (types.TargetedResults, error) {
ctx, cancel := context.WithTimeout(context.Background(), command.Timeout)
defer cancel()
var tr types.TargetedResults
FarmerURL := config.FarmerURL
targets, err := pki.ResolveTargets(target)
if err != nil {
return tr, err
Expand All @@ -30,7 +29,7 @@ func FRun(target string, command types.CmdRun) (types.TargetedResults, error) {
for _, sprout := range targets {
ta.Target = append(ta.Target, types.KeyManager{SproutID: sprout})
}
url := FarmerURL + "/cmd/run"
url := config.FarmerURL + "/cmd/run"
jw, _ := json.Marshal(ta)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(jw))
if err != nil {
Expand All @@ -43,7 +42,7 @@ func FRun(target string, command types.CmdRun) (types.TargetedResults, error) {
return tr, err
}
req.Header.Set("Authorization", newToken)
timeoutClient := http.Client{}
timeoutClient := &http.Client{}
timeoutClient.Timeout = command.Timeout
timeoutClient.Transport = pki.APIClient.Transport
resp, err := timeoutClient.Do(req)
Expand Down
10 changes: 8 additions & 2 deletions cmd/sprout/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ func natsInit(nc *nats.EncodedConn) error {
var cmdRun types.CmdRun
json.NewDecoder(bytes.NewBuffer(m.Data)).Decode(&cmdRun)
log.Trace(cmdRun)
results, _ := cmd.SRun(cmdRun)
resultsB, _ := json.Marshal(results)
results, err := cmd.SRun(cmdRun)
if err != nil {
log.Error(err)
}
resultsB, err := json.Marshal(results)
if err != nil {
log.Error(err)
}
m.Respond(resultsB)
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ingredients/cmd/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var envMutex sync.Mutex
func FRun(target types.KeyManager, cmdRun types.CmdRun) (types.CmdRun, error) {
topic := "grlx.sprouts." + target.SproutID + ".cmd.run"
var results types.CmdRun
err := ec.Request(topic, cmdRun, &results, time.Second*15+cmdRun.Duration)
err := ec.Request(topic, cmdRun, &results, time.Second*15+cmdRun.Timeout)
return results, err
}

Expand Down Expand Up @@ -100,5 +100,5 @@ func SRun(cmd types.CmdRun) (types.CmdRun, error) {
cmd.Stdout = stdoutBuf.String()
cmd.Stderr = stderrBuf.String()
cmd.ErrCode = command.ProcessState.ExitCode()
return cmd, nil
return cmd, err
}

0 comments on commit b08e2e8

Please sign in to comment.