mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-03-27 23:02:54 +00:00
Queue stats in drone-go
This commit is contained in:
parent
3534e92775
commit
2811185321
4 changed files with 68 additions and 0 deletions
|
@ -35,6 +35,7 @@ const (
|
|||
pathUsers = "%s/api/users"
|
||||
pathUser = "%s/api/users/%s"
|
||||
pathBuildQueue = "%s/api/builds"
|
||||
pathQueue = "%s/api/queue"
|
||||
pathVersion = "%s/version"
|
||||
)
|
||||
|
||||
|
@ -354,6 +355,13 @@ func (c *client) SecretDelete(owner, name, secret string) error {
|
|||
return c.delete(uri)
|
||||
}
|
||||
|
||||
func (c *client) QueueInfo() (*Info, error) {
|
||||
out := new(Info)
|
||||
uri := fmt.Sprintf(pathQueue+"/info", c.addr)
|
||||
err := c.get(uri, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
//
|
||||
// http request helper functions
|
||||
//
|
||||
|
|
46
drone-go/drone/client_test.go
Normal file
46
drone-go/drone/client_test.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package drone
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_QueueInfo(t *testing.T) {
|
||||
fixtureHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{
|
||||
"pending": null,
|
||||
"running": [
|
||||
{
|
||||
"id": "4696",
|
||||
"data": "",
|
||||
"labels": {
|
||||
"platform": "linux/amd64",
|
||||
"repo": "laszlocph/drone-oss-08"
|
||||
},
|
||||
"Dependencies": [],
|
||||
"DepStatus": {},
|
||||
"RunOn": null
|
||||
}
|
||||
],
|
||||
"stats": {
|
||||
"worker_count": 3,
|
||||
"pending_count": 0,
|
||||
"running_count": 1,
|
||||
"completed_count": 0
|
||||
},
|
||||
"Paused": false
|
||||
}`)
|
||||
}
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(fixtureHandler))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(ts.URL, http.DefaultClient)
|
||||
|
||||
info, err := client.QueueInfo()
|
||||
if info.Stats.Workers != 3 {
|
||||
t.Errorf("Unexpected worker count: %v, %v", info, err)
|
||||
}
|
||||
}
|
|
@ -122,4 +122,7 @@ type Client interface {
|
|||
|
||||
// SecretDelete deletes a secret.
|
||||
SecretDelete(owner, name, secret string) error
|
||||
|
||||
// QueueInfo returns the queue state.
|
||||
QueueInfo() (*Info, error)
|
||||
}
|
||||
|
|
|
@ -146,4 +146,15 @@ type (
|
|||
Version string `json:"version,omitempty"`
|
||||
Commit string `json:"commit,omitempty"`
|
||||
}
|
||||
|
||||
// Info provides queue stats.
|
||||
Info struct {
|
||||
Stats struct {
|
||||
Workers int `json:"worker_count"`
|
||||
Pending int `json:"pending_count"`
|
||||
Running int `json:"running_count"`
|
||||
Complete int `json:"completed_count"`
|
||||
} `json:"stats"`
|
||||
Paused bool `json:"paused,omitempty"`
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue