some initial work on a builtin build runner

This commit is contained in:
Brad Rydzewski
2015-05-05 01:04:20 -07:00
parent 51e995e0a1
commit 204fba9018
12 changed files with 624 additions and 45 deletions
+19 -6
View File
@@ -44,12 +44,11 @@ func (c *Client) Pull() *queue.Work {
}
// Pull makes an http request to the remote queue to
// retrieve work, with an acknowldement required.
// This initiates a long poll and will block until
// complete.
func (c *Client) PullAck() *queue.Work {
// retrieve work. This initiates a long poll and will
// block until complete.
func (c *Client) PullClose(cn queue.CloseNotifier) *queue.Work {
out := &queue.Work{}
err := c.send("POST", "/queue/pull?ack=true", nil, out)
err := c.send("POST", "/queue/pull", nil, out)
if err != nil {
// TODO handle error
}
@@ -96,7 +95,6 @@ func (c *Client) send(method, path string, in interface{}, out interface{}) erro
}
req.Header.Add("Authorization", "Bearer "+c.token)
req.Header.Add("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
@@ -107,3 +105,18 @@ func (c *Client) send(method, path string, in interface{}, out interface{}) erro
}
return json.NewDecoder(resp.Body).Decode(out)
}
// In order to implement PullClose() we'll need to use a custom transport:
//
// tr := &http.Transport{}
// client := &http.Client{Transport: tr}
// c := make(chan error, 1)
// go func() { c <- f(client.Do(req)) }()
// select {
// case <-ctx.Done():
// tr.CancelRequest(req)
// <-c // Wait for f to return.
// return ctx.Err()
// case err := <-c:
// return err
// }
+1 -6
View File
@@ -71,12 +71,7 @@ func remove(c *gin.Context) {
// to retrieve work.
func pull(c *gin.Context) {
q := fromContext(c)
var work *queue.Work
if c.Request.FormValue("ack") == "true" {
work = q.PullAck()
} else {
work = q.Pull()
}
work := q.PullClose(c.Writer)
if work == nil {
c.AbortWithStatus(500)
return