mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
some initial work on a builtin build runner
This commit is contained in:
+19
-6
@@ -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
|
||||
// }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user