1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00
woodpecker/pkg/queue/queue.go

46 lines
807 B
Go
Raw Normal View History

2014-02-07 13:10:01 +03:00
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
2014-02-07 13:10:01 +03:00
}
// 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)
2014-02-07 13:10:01 +03:00
queue := &Queue{tasks: tasks}
2014-02-07 13:10:01 +03:00
for i := 0; i < workers; i++ {
worker := worker{
runner: runner,
}
go worker.work(tasks)
2014-02-07 13:10:01 +03:00
}
return queue
2014-02-07 13:10:01 +03:00
}
// Add adds the task to the build queue.
func (q *Queue) Add(task *BuildTask) {
q.tasks <- task
2014-02-07 13:10:01 +03:00
}