Merge pull request #9774 from pwaller/cancellation

Add basic build cancellation
This commit is contained in:
Jessie Frazelle
2015-03-22 19:16:23 -07:00
11 changed files with 211 additions and 0 deletions
+2
View File
@@ -124,6 +124,8 @@ func (eng *Engine) Job(name string, args ...string) *Job {
Stderr: NewOutput(),
env: &Env{},
closeIO: true,
cancelled: make(chan struct{}),
}
if eng.Logging {
job.Stderr.Add(ioutils.NopWriteCloser(eng.Stderr))
+19
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"strings"
"sync"
"time"
log "github.com/Sirupsen/logrus"
@@ -34,6 +35,12 @@ type Job struct {
status Status
end time.Time
closeIO bool
// When closed, the job has been cancelled.
// Note: not all jobs implement cancellation.
// See Job.Cancel() and Job.WaitCancelled()
cancelled chan struct{}
cancelOnce sync.Once
}
type Status int
@@ -248,3 +255,15 @@ func (job *Job) StatusCode() int {
func (job *Job) SetCloseIO(val bool) {
job.closeIO = val
}
// When called, causes the Job.WaitCancelled channel to unblock.
func (job *Job) Cancel() {
job.cancelOnce.Do(func() {
close(job.cancelled)
})
}
// Returns a channel which is closed ("never blocks") when the job is cancelled.
func (job *Job) WaitCancelled() <-chan struct{} {
return job.cancelled
}