build runner now in charge of timeout

This commit is contained in:
Brad Rydzewski 2015-08-21 15:30:32 -07:00
parent bf1b9d2d8a
commit b264e837fe
2 changed files with 12 additions and 4 deletions

View file

@ -9,6 +9,7 @@ import (
"os/signal" "os/signal"
"strings" "strings"
"syscall" "syscall"
"time"
log "github.com/drone/drone/Godeps/_workspace/src/github.com/Sirupsen/logrus" log "github.com/drone/drone/Godeps/_workspace/src/github.com/Sirupsen/logrus"
"github.com/drone/drone/Godeps/_workspace/src/github.com/samalba/dockerclient" "github.com/drone/drone/Godeps/_workspace/src/github.com/samalba/dockerclient"
@ -63,9 +64,16 @@ func main() {
signal.Notify(killc, syscall.SIGINT, syscall.SIGTERM) signal.Notify(killc, syscall.SIGINT, syscall.SIGTERM)
go func() { go func() {
<-killc <-killc
log.Println("Received reques to kill this build") log.Println("Cancel request received, killing process")
client.Destroy() // possibe race here. implement lock on the other end client.Destroy() // possibe race here. implement lock on the other end
os.Exit(130) // cancel is treated like ctrl+c os.Exit(130) // cancel is treated like ctrl+c
}()
go func() {
<-time.After(time.Duration(ctx.Repo.Timeout) * time.Minute)
log.Println("Timeout request received, killing process")
client.Destroy() // possibe race here. implement lock on the other end
os.Exit(128) // cancel is treated like ctrl+c
}() }()
// performs some initial parsing and pre-processing steps // performs some initial parsing and pre-processing steps

View file

@ -242,7 +242,7 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, name st
return info, nil return info, nil
case err := <-errc: case err := <-errc:
return info, err return info, err
case <-time.After(timeout): // case <-time.After(timeout):
return info, ErrTimeout // return info, ErrTimeout
} }
} }