This commit is contained in:
Brad Rydzewski 2015-08-21 22:26:46 -07:00
parent b264e837fe
commit 27004bd61e
2 changed files with 15 additions and 30 deletions

View file

@ -154,14 +154,18 @@ func (r *Runner) Run(w *queue.Work) error {
return err return err
} }
worker := newWorkerTimeout(client, w.Repo.Timeout) worker := newWorker(client)
workers = append(workers, worker) workers = append(workers, worker)
cname := cname(job) cname := cname(job)
pullrequest := (w.Build.PullRequest != nil) pullrequest := (w.Build.PullRequest != nil)
state, builderr := worker.Build(cname, in, pullrequest) state, builderr := worker.Build(cname, in, pullrequest)
switch { switch {
case builderr == ErrTimeout: case state == 128:
job.ExitCode = state
job.Status = types.StateKilled
case state == 130:
job.ExitCode = state
job.Status = types.StateKilled job.Status = types.StateKilled
case builderr != nil: case builderr != nil:
job.Status = types.StateError job.Status = types.StateError

View file

@ -4,16 +4,12 @@ import (
"errors" "errors"
"io" "io"
"io/ioutil" "io/ioutil"
"time"
"github.com/drone/drone/Godeps/_workspace/src/github.com/samalba/dockerclient" "github.com/drone/drone/Godeps/_workspace/src/github.com/samalba/dockerclient"
"github.com/drone/drone/pkg/types" "github.com/drone/drone/pkg/types"
) )
var ( var ErrLogging = errors.New("Logs not available")
ErrTimeout = errors.New("Timeout")
ErrLogging = errors.New("Logs not available")
)
var ( var (
// options to fetch the stdout and stderr logs // options to fetch the stdout and stderr logs
@ -46,9 +42,6 @@ var (
// default arguments to invoke notify steps // default arguments to invoke notify steps
DefaultNotifyArgs = []string{"--notify"} DefaultNotifyArgs = []string{"--notify"}
// default arguments to invoke notify steps
DefaultNotifyTimeout = time.Minute * 5
) )
type work struct { type work struct {
@ -63,21 +56,13 @@ type work struct {
} }
type worker struct { type worker struct {
timeout time.Duration client dockerclient.Client
client dockerclient.Client build *dockerclient.ContainerInfo
build *dockerclient.ContainerInfo notify *dockerclient.ContainerInfo
notify *dockerclient.ContainerInfo
} }
func newWorker(client dockerclient.Client) *worker { func newWorker(client dockerclient.Client) *worker {
return newWorkerTimeout(client, 60) // default 60 minute timeout return &worker{client: client}
}
func newWorkerTimeout(client dockerclient.Client, timeout int64) *worker {
return &worker{
timeout: time.Duration(timeout) * time.Minute,
client: client,
}
} }
// Build executes the clone, build and deploy steps. // Build executes the clone, build and deploy steps.
@ -109,7 +94,7 @@ func (w *worker) Build(name string, stdin []byte, pr bool) (_ int, err error) {
// for the next few weeks // for the next few weeks
w.client.PullImage(conf.Image, nil) w.client.PullImage(conf.Image, nil)
w.build, err = run(w.client, conf, name, w.timeout) w.build, err = run(w.client, conf, name)
if err != nil { if err != nil {
return 1, err return 1, err
} }
@ -143,7 +128,7 @@ func (w *worker) Notify(stdin []byte) error {
} }
var err error var err error
w.notify, err = run(w.client, conf, "", DefaultNotifyTimeout) w.notify, err = run(w.client, conf, "")
return err return err
} }
@ -170,10 +155,8 @@ func (w *worker) Remove() {
} }
// run is a helper function that creates and starts a container, // run is a helper function that creates and starts a container,
// blocking until either complete or the timeout is reached. If // blocking until either complete.
// the timeout is reached an ErrTimeout is returned, else the func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, name string) (*dockerclient.ContainerInfo, error) {
// container info is returned.
func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, name string, timeout time.Duration) (*dockerclient.ContainerInfo, error) {
// attempts to create the contianer // attempts to create the contianer
id, err := client.CreateContainer(conf, name) id, err := client.CreateContainer(conf, name)
@ -242,7 +225,5 @@ 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):
// return info, ErrTimeout
} }
} }