Runner -> BuildRunner to be more descriptive

also kill some stale comments
This commit is contained in:
Alex Suraci 2014-02-25 17:14:14 -08:00
parent 9e1c4e60e5
commit a198657a7e
3 changed files with 10 additions and 18 deletions

View file

@ -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()

View file

@ -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,

View file

@ -17,7 +17,7 @@ import (
)
type worker struct {
runner Runner
runner BuildRunner
}
// work is a function that will infinitely