mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 21:51:33 +00:00
Merge pull request #9774 from pwaller/cancellation
Add basic build cancellation
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user