update agent logs

This commit is contained in:
Brad Rydzewski 2016-09-29 17:45:13 -04:00
parent 17a77127b6
commit 76b0286b68
3 changed files with 19 additions and 17 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/drone/drone/build"
"github.com/drone/drone/model"
"github.com/drone/mq/logger"
"github.com/drone/mq/stomp"
)
@ -27,7 +28,7 @@ func NewClientUpdater(client *stomp.Client) UpdateFunc {
return func(w *model.Work) {
err := client.SendJSON("/queue/updates", w)
if err != nil {
logrus.Errorf("Error updating %s/%s#%d.%d. %s",
logger.Warningf("Error updating %s/%s#%d.%d. %s",
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err)
}
if w.Job.Status != model.StatusRunning {
@ -38,7 +39,7 @@ func NewClientUpdater(client *stomp.Client) UpdateFunc {
}
if err := client.Send(dest, []byte("eof"), opts...); err != nil {
logrus.Errorf("Error sending eof %s/%s#%d.%d. %s",
logger.Warningf("Error sending eof %s/%s#%d.%d. %s",
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err)
}
}

View file

@ -175,7 +175,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
}
p.containers = append(p.containers, name)
logrus.Debugf("wait.add(1) for %s logs", name)
p.wait.Add(1)
go func() {
defer func() {
@ -183,7 +182,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
logrus.Errorln("recover writing build output", r)
}
logrus.Debugf("wait.done() for %s logs", name)
p.wait.Done()
}()
@ -217,7 +215,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
return err
}
logrus.Debugf("wait.add(1) for %s exit code", name)
p.wait.Add(1)
go func() {
defer func() {
@ -225,7 +222,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
logrus.Errorln("recover writing exit code to output", r)
}
p.wait.Done()
logrus.Debugf("wait.done() for %s exit code", name)
}()
p.pipe <- &Line{

View file

@ -9,7 +9,9 @@ import (
"time"
"github.com/drone/drone/model"
"github.com/drone/mq/logger"
"github.com/drone/mq/stomp"
"github.com/tidwall/redlog"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
@ -136,9 +138,15 @@ var AgentCmd = cli.Command{
func start(c *cli.Context) {
log := redlog.New(os.Stderr)
log.SetLevel(0)
logger.SetLogger(log)
// debug level if requested by user
if c.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
log.SetLevel(1)
} else {
logrus.SetLevel(logrus.WarnLevel)
}
@ -152,10 +160,7 @@ func start(c *cli.Context) {
accessToken = c.String("drone-token")
}
logrus.Infof("Connecting to %s with token %s",
c.String("drone-server"),
accessToken,
)
logger.Noticef("connecting to server%s", c.String("drone-server"))
server := strings.TrimRight(c.String("drone-server"), "/")
@ -203,7 +208,7 @@ func start(c *cli.Context) {
// dial the drone server to establish a TCP connection.
client, err = stomp.Dial(server)
if err != nil {
logrus.Errorf("Failed to establish server connection, %s, retry in %v", err, backoff)
logger.Warningf("connection failed, retry in %v. %s", backoff, err)
<-time.After(backoff)
continue
}
@ -213,7 +218,7 @@ func start(c *cli.Context) {
// initialize the stomp session and authenticate.
if err = client.Connect(opts...); err != nil {
logrus.Errorf("Failed to establish server session, %s, retry in %v", err, backoff)
logger.Warningf("session failed, retry in %v", backoff, err)
<-time.After(backoff)
continue
}
@ -233,10 +238,10 @@ func start(c *cli.Context) {
go handler(m) // HACK until we a channel based Subscribe implementation
}), opts...)
logrus.Infof("Server connection establish, ready to process builds.")
logger.Noticef("connection establish, ready to process builds.")
<-client.Done()
logrus.Warnf("Server connection interrupted, attempting to reconnect.")
logger.Warningf("connection interrupted, attempting to reconnect.")
}
}
@ -251,10 +256,10 @@ func handleSignals() {
go func() {
<-c
logrus.Debugln("SIGTERM received.")
logrus.Debugln("wait for running builds to finish.")
logger.Warningf("SIGTERM received.")
logger.Warningf("wait for running builds to finish.")
running.Wait()
logrus.Debugln("done.")
logger.Warningf("done.")
os.Exit(0)
}()
}