1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

ability to add and remove workers

This commit is contained in:
Brad Rydzewski 2014-10-08 21:55:53 -07:00
parent 33721e54aa
commit 17d773fac0
2 changed files with 25 additions and 3 deletions

View File

@ -31,12 +31,32 @@ func GetWorkers(c web.C, w http.ResponseWriter, r *http.Request) {
//
func PostWorker(c web.C, w http.ResponseWriter, r *http.Request) {
ctx := context.FromC(c)
workers := pool.FromContext(ctx)
node := r.FormValue("node")
workers.Allocate(docker.NewHost(node))
pool := pool.FromContext(ctx)
node := r.FormValue("address")
pool.Allocate(docker.NewHost(node))
w.WriteHeader(http.StatusOK)
}
// Delete accepts a request to delete a worker
// from the pool.
//
// DELETE /api/workers
//
func DelWorker(c web.C, w http.ResponseWriter, r *http.Request) {
ctx := context.FromC(c)
pool := pool.FromContext(ctx)
uuid := r.FormValue("id")
for _, worker := range pool.List() {
if worker.(*docker.Docker).UUID != uuid {
pool.Deallocate(worker)
w.WriteHeader(http.StatusNoContent)
return
}
}
w.WriteHeader(http.StatusNotFound)
}
// GetWorkPending accepts a request to retrieve the list
// of pending work and returns in JSON format.
//

View File

@ -163,6 +163,8 @@ func main() {
work.Get("/api/work/pending", handler.GetWorkPending)
work.Get("/api/work/assignments", handler.GetWorkAssigned)
work.Get("/api/workers", handler.GetWorkers)
work.Post("/api/workers", handler.PostWorker)
work.Delete("/api/workers", handler.DelWorker)
goji.Handle("/api/work*", work)
// Include static resources