Skip to content

Commit

Permalink
Merge pull request #129 from berty/dev/moul/buildkite-running
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Apr 29, 2020
2 parents 833861e + d998410 commit e2ac2e8
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pkg/yolosvc/driver_buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,33 @@ func (svc *service) BuildkiteWorker(ctx context.Context, opts BuildkiteWorkerOpt
logger.Warn("get last buildkite build created time", zap.Error(err))
}
logger.Debug("buildkite: refresh", zap.Int("iteration", iteration), zap.Time("since", since))
// FIXME: only fetch builds since most recent known
batch, err := fetchBuildkiteBuilds(ctx, svc.bkc, since, maxPages, logger)

// fetch recent builds
callOpts := buildkite.BuildsListOptions{
FinishedFrom: since,
}
batch, err := fetchBuildkiteBuilds(ctx, svc.bkc, since, maxPages, callOpts, logger)
if err != nil {
logger.Warn("fetch buildkite", zap.Error(err))
} else {
if err := svc.saveBatch(ctx, batch); err != nil {
logger.Warn("save batch", zap.Error(err))
}
}

// always fetch "running" builds even if they are already known (to update last states)
callOpts = buildkite.BuildsListOptions{
State: []string{"running", "scheduled"},
}
batch, err = fetchBuildkiteBuilds(ctx, svc.bkc, since, maxPages, callOpts, logger)
if err != nil {
logger.Warn("fetch buildkite", zap.Error(err))
} else {
if err := svc.saveBatch(ctx, batch); err != nil {
logger.Warn("save batch", zap.Error(err))
}
}

// FIXME: fetch artifacts for builds with job that are successful and have a not empty artifact path

if opts.Once {
Expand All @@ -59,15 +77,12 @@ func (svc *service) BuildkiteWorker(ctx context.Context, opts BuildkiteWorkerOpt
}
}

func fetchBuildkiteBuilds(ctx context.Context, bkc *buildkite.Client, since time.Time, maxPages int, logger *zap.Logger) (*yolopb.Batch, error) {
func fetchBuildkiteBuilds(ctx context.Context, bkc *buildkite.Client, since time.Time, maxPages int, callOpts buildkite.BuildsListOptions, logger *zap.Logger) (*yolopb.Batch, error) {
batch := yolopb.NewBatch()
total := 0
callOpts := &buildkite.BuildsListOptions{
FinishedFrom: since,
}
for i := 0; i < maxPages; i++ {
before := time.Now()
builds, resp, err := bkc.Builds.List(callOpts)
builds, resp, err := bkc.Builds.List(&callOpts)
if err != nil {
return nil, fmt.Errorf("buildkite.Builds.List: %w", err)
}
Expand Down

0 comments on commit e2ac2e8

Please sign in to comment.