harness-drone/pkg/queue/queue.go
Alex Suraci a198657a7e Runner -> BuildRunner to be more descriptive
also kill some stale comments
2014-02-25 17:14:14 -08:00

45 lines
807 B
Go

package queue
import (
"github.com/drone/drone/pkg/build/script"
. "github.com/drone/drone/pkg/model"
)
// A Queue dispatches tasks to workers.
type Queue struct {
tasks chan<- *BuildTask
}
// BuildTasks represents a build that is pending
// execution.
type BuildTask struct {
Repo *Repo
Commit *Commit
Build *Build
// Build instructions from the .drone.yml
// file, unmarshalled.
Script *script.Build
}
// Start N workers with the given build runner.
func Start(workers int, runner BuildRunner) *Queue {
tasks := make(chan *BuildTask)
queue := &Queue{tasks: tasks}
for i := 0; i < workers; i++ {
worker := worker{
runner: runner,
}
go worker.work(tasks)
}
return queue
}
// Add adds the task to the build queue.
func (q *Queue) Add(task *BuildTask) {
q.tasks <- task
}