MCPcopy
hub / github.com/keploy/keploy / requestAgentStop

Method requestAgentStop

pkg/platform/http/agent.go:1096–1124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1094}
1095
1096func (a *AgentClient) requestAgentStop() error {
1097 if a.conf == nil {
1098 return fmt.Errorf("agent config is nil")
1099 }
1100 if a.conf.Agent.AgentURI == "" {
1101 return fmt.Errorf("agent URI is not configured")
1102 }
1103
1104 stopCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1105 defer cancel()
1106
1107 req, err := http.NewRequestWithContext(stopCtx, http.MethodPost, fmt.Sprintf("%s/stop", a.conf.Agent.AgentURI), nil)
1108 if err != nil {
1109 return err
1110 }
1111
1112 res, err := a.client.Do(req)
1113 if err != nil {
1114 return err
1115 }
1116 defer res.Body.Close()
1117
1118 if res.StatusCode != http.StatusOK {
1119 body, _ := io.ReadAll(res.Body)
1120 return fmt.Errorf("agent stop http %d: %s", res.StatusCode, strings.TrimSpace(string(body)))
1121 }
1122
1123 return nil
1124}
1125
1126// stopAgent stops the agent process gracefully.
1127func (a *AgentClient) stopAgent() {

Callers 2

startNativeAgentMethod · 0.95

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected