ability to pause and resume build queue
This commit is contained in:
parent
680afa1db1
commit
bd23f21ff4
9 changed files with 94 additions and 46 deletions
|
@ -44,6 +44,14 @@ type Scheduler interface {
|
||||||
// returns true if the build has been cancelled.
|
// returns true if the build has been cancelled.
|
||||||
Cancelled(context.Context, int64) (bool, error)
|
Cancelled(context.Context, int64) (bool, error)
|
||||||
|
|
||||||
|
// Pause pauses the scheduler and prevents new pipelines
|
||||||
|
// from being scheduled for execution.
|
||||||
|
Pause(context.Context) error
|
||||||
|
|
||||||
|
// Resume unpauses the scheduler, allowing new pipelines
|
||||||
|
// to be scheduled for execution.
|
||||||
|
Resume(context.Context) error
|
||||||
|
|
||||||
// Stats provides statistics for underlying scheduler. The
|
// Stats provides statistics for underlying scheduler. The
|
||||||
// data format is scheduler-specific.
|
// data format is scheduler-specific.
|
||||||
Stats(context.Context) (interface{}, error)
|
Stats(context.Context) (interface{}, error)
|
||||||
|
|
|
@ -249,8 +249,8 @@ func (s Server) Handler() http.Handler {
|
||||||
r.Route("/queue", func(r chi.Router) {
|
r.Route("/queue", func(r chi.Router) {
|
||||||
r.Use(acl.AuthorizeAdmin)
|
r.Use(acl.AuthorizeAdmin)
|
||||||
r.Get("/", queue.HandleItems(s.Stages))
|
r.Get("/", queue.HandleItems(s.Stages))
|
||||||
// r.Post("/", queue.HandleResume(s.Queue))
|
r.Post("/", queue.HandleResume(s.Scheduler))
|
||||||
// r.Delete("/", queue.HandlePause(s.Queue))
|
r.Delete("/", queue.HandlePause(s.Scheduler))
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Route("/user", func(r chi.Router) {
|
r.Route("/user", func(r chi.Router) {
|
||||||
|
|
|
@ -30,3 +30,11 @@ var notImplemented = func(w http.ResponseWriter, r *http.Request) {
|
||||||
func HandleItems(store core.StageStore) http.HandlerFunc {
|
func HandleItems(store core.StageStore) http.HandlerFunc {
|
||||||
return notImplemented
|
return notImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandlePause(core.Scheduler) http.HandlerFunc {
|
||||||
|
return notImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleResume(core.Scheduler) http.HandlerFunc {
|
||||||
|
return notImplemented
|
||||||
|
}
|
||||||
|
|
|
@ -6,26 +6,26 @@
|
||||||
|
|
||||||
package queue
|
package queue
|
||||||
|
|
||||||
// import (
|
import (
|
||||||
// "net/http"
|
"net/http"
|
||||||
|
|
||||||
// "github.com/drone/drone/core"
|
"github.com/drone/drone/core"
|
||||||
// "github.com/drone/drone/handler/api/render"
|
"github.com/drone/drone/handler/api/render"
|
||||||
// "github.com/drone/drone/logger"
|
"github.com/drone/drone/logger"
|
||||||
// )
|
)
|
||||||
|
|
||||||
// // HandlePause returns an http.HandlerFunc that processes
|
// HandlePause returns an http.HandlerFunc that processes
|
||||||
// // an http.Request to pause the queue.
|
// an http.Request to pause the scheduler.
|
||||||
// func HandlePause(queue core.Queue) http.HandlerFunc {
|
func HandlePause(scheduler core.Scheduler) http.HandlerFunc {
|
||||||
// return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// ctx := r.Context()
|
ctx := r.Context()
|
||||||
// err := queue.Pause(ctx)
|
err := scheduler.Pause(ctx)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// render.InternalError(w, err)
|
render.InternalError(w, err)
|
||||||
// logger.FromRequest(r).WithError(err).
|
logger.FromRequest(r).WithError(err).
|
||||||
// Errorln("api: cannot pause queue")
|
Errorln("api: cannot pause scheduler")
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
|
@ -6,26 +6,26 @@
|
||||||
|
|
||||||
package queue
|
package queue
|
||||||
|
|
||||||
// import (
|
import (
|
||||||
// "net/http"
|
"net/http"
|
||||||
|
|
||||||
// "github.com/drone/drone/core"
|
"github.com/drone/drone/core"
|
||||||
// "github.com/drone/drone/handler/api/render"
|
"github.com/drone/drone/handler/api/render"
|
||||||
// "github.com/drone/drone/logger"
|
"github.com/drone/drone/logger"
|
||||||
// )
|
)
|
||||||
|
|
||||||
// // HandleResume returns an http.HandlerFunc that processes
|
// HandleResume returns an http.HandlerFunc that processes
|
||||||
// // an http.Request to pause the queue.
|
// an http.Request to pause the scheduler.
|
||||||
// func HandleResume(queue core.Queue) http.HandlerFunc {
|
func HandleResume(scheduler core.Scheduler) http.HandlerFunc {
|
||||||
// return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// ctx := r.Context()
|
ctx := r.Context()
|
||||||
// err := queue.Resume(ctx)
|
err := scheduler.Resume(ctx)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// render.InternalError(w, err)
|
render.InternalError(w, err)
|
||||||
// logger.FromRequest(r).WithError(err).
|
logger.FromRequest(r).WithError(err).
|
||||||
// Errorln("api: cannot resume queue")
|
Errorln("api: cannot resume scheduler")
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func (s *kubeScheduler) Schedule(ctx context.Context, stage *core.Stage) error {
|
||||||
GenerateName: name,
|
GenerateName: name,
|
||||||
Namespace: s.namespace(),
|
Namespace: s.namespace(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"io.drone": "true",
|
"io.drone": "true",
|
||||||
"io.drone.stage.created": time.Unix(stage.Created, 0).String(),
|
"io.drone.stage.created": time.Unix(stage.Created, 0).String(),
|
||||||
"io.drone.stage.scheduled": time.Now().String(),
|
"io.drone.stage.scheduled": time.Now().String(),
|
||||||
"io.drone.stage.id": fmt.Sprint(stage.ID),
|
"io.drone.stage.id": fmt.Sprint(stage.ID),
|
||||||
|
@ -201,6 +201,14 @@ func (s *kubeScheduler) Stats(_ context.Context) (interface{}, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *kubeScheduler) Pause(context.Context) error {
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *kubeScheduler) Resume(context.Context) error {
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *kubeScheduler) namespace() string {
|
func (s *kubeScheduler) namespace() string {
|
||||||
namespace := s.config.Namespace
|
namespace := s.config.Namespace
|
||||||
if namespace == "" {
|
if namespace == "" {
|
||||||
|
|
|
@ -48,3 +48,11 @@ func (noop) Cancelled(context.Context, int64) (bool, error) {
|
||||||
func (noop) Stats(context.Context) (interface{}, error) {
|
func (noop) Stats(context.Context) (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (noop) Pause(context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (noop) Resume(context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (s *nomadScheduler) Schedule(ctx context.Context, stage *core.Stage) error
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Meta: map[string]string{
|
Meta: map[string]string{
|
||||||
"io.drone": "true",
|
"io.drone": "true",
|
||||||
"io.drone.stage.created": time.Unix(stage.Created, 0).String(),
|
"io.drone.stage.created": time.Unix(stage.Created, 0).String(),
|
||||||
"io.drone.stage.scheduled": time.Now().String(),
|
"io.drone.stage.scheduled": time.Now().String(),
|
||||||
"io.drone.stage.id": fmt.Sprint(stage.ID),
|
"io.drone.stage.id": fmt.Sprint(stage.ID),
|
||||||
|
@ -206,6 +206,14 @@ func (s *nomadScheduler) Stats(context.Context) (interface{}, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *nomadScheduler) Pause(context.Context) error {
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *nomadScheduler) Resume(context.Context) error {
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// stringToPtr returns the pointer to a string
|
// stringToPtr returns the pointer to a string
|
||||||
func stringToPtr(str string) *string {
|
func stringToPtr(str string) *string {
|
||||||
return &str
|
return &str
|
||||||
|
|
|
@ -48,3 +48,11 @@ func (noop) Cancelled(context.Context, int64) (bool, error) {
|
||||||
func (noop) Stats(context.Context) (interface{}, error) {
|
func (noop) Stats(context.Context) (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (noop) Pause(context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (noop) Resume(context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue