1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-01-23 17:53:23 +02:00

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" "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) 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 dockerClient *docker.Client
timeout time.Duration timeout time.Duration
} }
func NewRunner(dockerClient *docker.Client, timeout time.Duration) Runner { func NewBuildRunner(dockerClient *docker.Client, timeout time.Duration) BuildRunner {
return &runner{ return &buildRunner{
dockerClient: dockerClient, dockerClient: dockerClient,
timeout: timeout, timeout: timeout,
} }
} }
func (r *runner) Run(buildScript *script.Build, repo *repo.Repo, key []byte, buildOutput io.Writer) (bool, error) { func (runner *buildRunner) Run(buildScript *script.Build, repo *repo.Repo, key []byte, buildOutput io.Writer) (bool, error) {
builder := build.New(r.dockerClient) builder := build.New(runner.dockerClient)
builder.Build = buildScript builder.Build = buildScript
builder.Repo = repo builder.Repo = repo
builder.Key = key builder.Key = key
builder.Stdout = buildOutput builder.Stdout = buildOutput
builder.Timeout = r.timeout builder.Timeout = runner.timeout
err := builder.Run() err := builder.Run()

View File

@ -22,20 +22,12 @@ type BuildTask struct {
Script *script.Build Script *script.Build
} }
func Start(workers int, runner Runner) *Queue { // Start N workers with the given build runner.
// get the number of CPUs. Since builds func Start(workers int, runner BuildRunner) *Queue {
// tend to be CPU-intensive we should only
// execute 1 build per CPU.
// must be at least 1
// if ncpu < 1 {
// ncpu = 1
// }
tasks := make(chan *BuildTask) tasks := make(chan *BuildTask)
queue := &Queue{tasks: tasks} queue := &Queue{tasks: tasks}
// spawn a worker for each CPU
for i := 0; i < workers; i++ { for i := 0; i < workers; i++ {
worker := worker{ worker := worker{
runner: runner, runner: runner,

View File

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