1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/pkg/queue/queue.go
2014-05-22 23:16:01 -04:00

41 lines
674 B
Go

package queue
import (
. "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
}
// 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
}