Put cmd.Start() and cmd.Wait() in a loop so keybase restarts if it dies

This commit is contained in:
Sam
2019-07-02 21:09:37 -04:00
parent 51796165cf
commit 354fa145e1

View File

@ -155,9 +155,10 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
} }
keybaseListen := exec.Command(k.Path, execCommand...) keybaseListen := exec.Command(k.Path, execCommand...)
keybaseOutput, _ := keybaseListen.StdoutPipe() keybaseOutput, _ := keybaseListen.StdoutPipe()
for {
keybaseListen.Start() keybaseListen.Start()
scanner := bufio.NewScanner(keybaseOutput) scanner := bufio.NewScanner(keybaseOutput)
go func(scanner *bufio.Scanner, c chan<- ChatIn) { go func(scanner *bufio.Scanner, c chan<- ChatIn) {
var jsonData ChatIn var jsonData ChatIn
for scanner.Scan() { for scanner.Scan() {
@ -167,6 +168,7 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
}(scanner, c) }(scanner, c)
keybaseListen.Wait() keybaseListen.Wait()
} }
}
// Run() runs keybase chat api-listen, and passes incoming messages to the message handler func // Run() runs keybase chat api-listen, and passes incoming messages to the message handler func
func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) { func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) {