Skip to content

Commit

Permalink
only run builds locally if the resources fit
Browse files Browse the repository at this point in the history
  • Loading branch information
damoon committed Nov 23, 2020
1 parent 31d8579 commit b31008e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,28 @@ func (s Service) build(w http.ResponseWriter, r *http.Request) {
return
}

ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()

scheduler := s.buildInKubernetes
err = semBuild.Acquire(ctx, 1)
if err == nil {
log.Printf("build locally %v", cfg.tags)
defer semBuild.Release(1)
scheduler = buildLocally
} else {
log.Printf("build scheduled %v", cfg.tags)
if cfg.fitsLocally() {
ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
defer cancel()

err = semBuild.Acquire(ctx, 1)
if err == nil {
log.Printf("build locally %v", cfg.tags)
defer semBuild.Release(1)
scheduler = buildLocally
} else {
log.Printf("build scheduled %v", cfg.tags)
}
}

scheduler(w, r, cfg)
}

func (c buildConfig) fitsLocally() bool {
return c.cpuMilliseconds <= 1000 && c.memoryBytes <= 1024*1024*1024*2
}

func buildParameters(r *http.Request) (*buildConfig, error) {
cfg := &buildConfig{}

Expand Down

0 comments on commit b31008e

Please sign in to comment.