MCPcopy
hub / github.com/sourcegraph/checkup / doChecks

Method doChecks

check/exec/exec.go:97–130  ·  view source on GitHub ↗

doChecks executes command and returns each attempt.

()

Source from the content-addressed store, hash-verified

95
96// doChecks executes command and returns each attempt.
97func (c Checker) doChecks() types.Attempts {
98 checks := make(types.Attempts, c.Attempts)
99 for i := 0; i < c.Attempts; i++ {
100 start := time.Now()
101
102 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
103 defer cancel()
104
105 command := exec.CommandContext(ctx, c.Command, c.Arguments...)
106 output, err := command.CombinedOutput()
107
108 checks[i].RTT = time.Since(start)
109
110 if err != nil {
111 stringify := func(s string) string {
112 if strings.TrimSpace(s) == "" {
113 return "empty"
114 }
115 return s
116 }
117 checks[i].Error = fmt.Sprintf("Error: %s\nOutput: %s\n", err.Error(), stringify(string(output)))
118 continue
119 }
120
121 if err := c.checkDown(string(output)); err != nil {
122 checks[i].Error = err.Error()
123 }
124
125 if c.AttemptSpacing > 0 {
126 time.Sleep(c.AttemptSpacing)
127 }
128 }
129 return checks
130}
131
132// conclude takes the data in result from the attempts and
133// computes remaining values needed to fill out the result.

Callers 1

CheckMethod · 0.95

Implementers 6

fakecheckup_test.go
Checkercheck/http/http.go
Checkercheck/dns/dns.go
Checkercheck/exec/exec.go
Checkercheck/tls/tls.go
Checkercheck/tcp/tcp.go

Calls 2

checkDownMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected