mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 19:31:05 +00:00
Runner -> BuildRunner to be more descriptive
also kill some stale comments
This commit is contained in:
parent
9e1c4e60e5
commit
a198657a7e
3 changed files with 10 additions and 18 deletions
|
@ -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()
|
||||
|
|
@ -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,
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
type worker struct {
|
||||
runner Runner
|
||||
runner BuildRunner
|
||||
}
|
||||
|
||||
// work is a function that will infinitely
|
||||
|
|
Loading…
Reference in a new issue