github.com/unclejack/drone@v0.2.1-0.20140918182345-831b034aa33b/pkg/queue/queue.go (about) 1 package queue 2 3 import ( 4 . "github.com/drone/drone/pkg/model" 5 ) 6 7 // A Queue dispatches tasks to workers. 8 type Queue struct { 9 tasks chan<- *BuildTask 10 } 11 12 // BuildTasks represents a build that is pending 13 // execution. 14 type BuildTask struct { 15 Repo *Repo 16 Commit *Commit 17 Build *Build 18 } 19 20 // Start N workers with the given build runner. 21 func Start(workers int, runner BuildRunner) *Queue { 22 tasks := make(chan *BuildTask) 23 24 queue := &Queue{tasks: tasks} 25 26 for i := 0; i < workers; i++ { 27 worker := worker{ 28 runner: runner, 29 } 30 31 go worker.work(tasks) 32 } 33 34 return queue 35 } 36 37 // Add adds the task to the build queue. 38 func (q *Queue) Add(task *BuildTask) { 39 q.tasks <- task 40 }