drone exec and drone agent now share code

This commit is contained in:
Brad Rydzewski
2016-05-10 17:03:24 -07:00
parent 8f467ff5ca
commit 850c00dbba
10 changed files with 79 additions and 232 deletions

View File

@@ -62,6 +62,7 @@ func (a *Agent) Run(payload *queue.Work, cancel <-chan bool) error {
a.Update(payload)
return err
}
a.Update(payload)
err = a.exec(spec, payload, cancel)
if err != nil {

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"sync"
"time"
"github.com/Sirupsen/logrus"
@@ -41,10 +42,21 @@ func NewClientUpdater(client client.Client) UpdateFunc {
}
}
func NewClientLogger(w io.Writer) LoggerFunc {
func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.WriteCloser) LoggerFunc {
var once sync.Once
return func(line *build.Line) {
// annoying hack to only start streaming once the first line is written
once.Do(func() {
go func() {
err := client.Stream(id, rc)
if err != nil && err != io.ErrClosedPipe {
logrus.Errorf("Error streaming build logs. %s", err)
}
}()
})
linejson, _ := json.Marshal(line)
w.Write(linejson)
w.Write([]byte{'\n'})
wc.Write(linejson)
wc.Write([]byte{'\n'})
}
}