Remove unused function readResultsFromCommand

Signed-off-by: AKU <tom@tdpain.net>
This commit is contained in:
akp 2021-12-25 18:29:26 +00:00
parent a23e78200a
commit 6821184fe1
No known key found for this signature in database
GPG key ID: AA5726202C8879B7

View file

@ -2,16 +2,12 @@ package runners
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"os/exec"
"strings"
"sync"
"time"
au "github.com/logrusorgru/aurora"
)
type Task struct {
@ -84,7 +80,7 @@ func checkWait(cmd *exec.Cmd) ([]byte, error) {
if err == nil {
return e, nil
}
if cmd.ProcessState != nil {
// this is only populated after program exit - we have an issue
return nil, fmt.Errorf("run failed with exit code %d: %s", cmd.ProcessState.ExitCode(), cmd.Stderr.(*bytes.Buffer).String())
@ -93,65 +89,3 @@ func checkWait(cmd *exec.Cmd) ([]byte, error) {
time.Sleep(time.Millisecond * 10)
}
}
func readResultsFromCommand(cmd *exec.Cmd) chan ResultOrError {
stdoutWriter := &customWriter{}
stderrBuffer := new(bytes.Buffer)
cmd.Stdout = stdoutWriter
cmd.Stderr = stderrBuffer
err := cmd.Start()
if err != nil {
return makeErrorChan(err)
}
// Command status listener
status := make(chan bool) // true if success, false if failure
go func() {
_ = cmd.Wait()
status <- cmd.ProcessState.Success()
close(status)
}()
// Now let's read some results
c := make(chan ResultOrError)
go func() {
readerLoop:
for {
inp, err := stdoutWriter.GetEntry()
// will return an error if there is nothing to retrieve
if err == nil {
res := new(Result)
err = json.Unmarshal(inp, res)
if err != nil {
// echo anything that won't parse to stdout (this lets us add debug print statements)
fmt.Printf("[%s] %v\n", au.BrightRed("DBG"), strings.TrimSpace(string(inp)))
} else {
c <- ResultOrError{Result: res}
}
}
select {
case successfulFinish := <-status:
if !successfulFinish {
c <- ResultOrError{Error: errors.New("run failed: " + stderrBuffer.String())}
}
break readerLoop
default:
}
}
close(c)
_ = cmd.Process.Kill()
}()
return c
}