From cb039a0f7ab9af44ad006c6bd15ad34f882f13cb Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 8 Jun 2020 11:13:40 -0400 Subject: [PATCH] use multierror in reaper --- service/canceler/reaper/reaper.go | 46 +++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/service/canceler/reaper/reaper.go b/service/canceler/reaper/reaper.go index 8182ff09..6974588c 100644 --- a/service/canceler/reaper/reaper.go +++ b/service/canceler/reaper/reaper.go @@ -21,6 +21,7 @@ import ( "github.com/drone/drone/core" + "github.com/hashicorp/go-multierror" "github.com/sirupsen/logrus" ) @@ -85,28 +86,35 @@ func (r *Reaper) reap(ctx context.Context) error { } }() - // TODO debug log entry - // TODO use multierror + logrus.Traceln("reaper: finding zombie builds") + var result error pending, err := r.Builds.Pending(ctx) if err != nil { logrus.WithError(err). Errorf("reaper: cannot get pending builds") - return err + result = multierror.Append(result, err) } for _, build := range pending { + logger := logrus. + WithField("build.id", build.ID). + WithField("build.number", build.Number). + WithField("build.repo_id", build.RepoID). + WithField("build.status", build.Status). + WithField("build.created", build.Created) + // if a build is pending for longer than the maximum // pending time limit, the build is maybe cancelled. if isExceeded(build.Created, r.Pending, buffer) { - // TODO debug log entry + logger.Traceln("reaper: cancel build: time limit exceeded") err = r.reapMaybe(ctx, build) if err != nil { - // TODO error log entry - return err + logger.WithError(err). + Errorln("reaper: cannot cancel build") + result = multierror.Append(result, err) } - // TODO debug log entry } else { - // TODO trace log entry + logger.Traceln("reaper: ignore build: time limit not exceeded") } } @@ -114,25 +122,33 @@ func (r *Reaper) reap(ctx context.Context) error { if err != nil { logrus.WithError(err). Errorf("reaper: cannot get running builds") - return err + result = multierror.Append(result, err) } for _, build := range running { + logger := logrus. + WithField("build.id", build.ID). + WithField("build.number", build.Number). + WithField("build.repo_id", build.RepoID). + WithField("build.status", build.Status). + WithField("build.created", build.Created) + // if a build is running for longer than the maximum // running time limit, the build is maybe cancelled. if isExceeded(build.Started, r.Running, buffer) { - // TODO debug log entry + logger.Traceln("reaper: cancel build: time limit exceeded") + err = r.reapMaybe(ctx, build) if err != nil { - // TODO error log entry - return err + logger.WithError(err). + Errorln("reaper: cannot cancel build") + result = multierror.Append(result, err) } - // TODO debug log entry } else { - // TODO trace log entry + logger.Traceln("reaper: ignore build: time limit not exceeded") } } - return nil + return result } func (r *Reaper) reapMaybe(ctx context.Context, build *core.Build) error {