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