diff --git a/pkg/queue/runner.go b/pkg/queue/build_runner.go similarity index 63% rename from pkg/queue/runner.go rename to pkg/queue/build_runner.go index 41a435316..0c04ad102 100644 --- a/pkg/queue/runner.go +++ b/pkg/queue/build_runner.go @@ -10,29 +10,29 @@ import ( "github.com/drone/drone/pkg/build/script" ) -type Runner interface { +type BuildRunner interface { Run(buildScript *script.Build, repo *repo.Repo, key []byte, buildOutput io.Writer) (success bool, err error) } -type runner struct { +type buildRunner struct { dockerClient *docker.Client timeout time.Duration } -func NewRunner(dockerClient *docker.Client, timeout time.Duration) Runner { - return &runner{ +func NewBuildRunner(dockerClient *docker.Client, timeout time.Duration) BuildRunner { + return &buildRunner{ dockerClient: dockerClient, timeout: timeout, } } -func (r *runner) Run(buildScript *script.Build, repo *repo.Repo, key []byte, buildOutput io.Writer) (bool, error) { - builder := build.New(r.dockerClient) +func (runner *buildRunner) Run(buildScript *script.Build, repo *repo.Repo, key []byte, buildOutput io.Writer) (bool, error) { + builder := build.New(runner.dockerClient) builder.Build = buildScript builder.Repo = repo builder.Key = key builder.Stdout = buildOutput - builder.Timeout = r.timeout + builder.Timeout = runner.timeout err := builder.Run() diff --git a/pkg/queue/queue.go b/pkg/queue/queue.go index ccac7a161..cb7cfba96 100644 --- a/pkg/queue/queue.go +++ b/pkg/queue/queue.go @@ -22,20 +22,12 @@ type BuildTask struct { Script *script.Build } -func Start(workers int, runner Runner) *Queue { - // get the number of CPUs. Since builds - // tend to be CPU-intensive we should only - // execute 1 build per CPU. - // must be at least 1 - // if ncpu < 1 { - // ncpu = 1 - // } - +// Start N workers with the given build runner. +func Start(workers int, runner BuildRunner) *Queue { tasks := make(chan *BuildTask) queue := &Queue{tasks: tasks} - // spawn a worker for each CPU for i := 0; i < workers; i++ { worker := worker{ runner: runner, diff --git a/pkg/queue/worker.go b/pkg/queue/worker.go index a43071091..58a3b669d 100644 --- a/pkg/queue/worker.go +++ b/pkg/queue/worker.go @@ -17,7 +17,7 @@ import ( ) type worker struct { - runner Runner + runner BuildRunner } // work is a function that will infinitely