From 8bb5770636afaa42a54f294854cccd2d1285cc63 Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Fri, 28 Jun 2019 08:42:06 +0200 Subject: [PATCH] Endpoint that blocks until there are running builds --- router/router.go | 4 ++++ server/hook.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/router/router.go b/router/router.go index 5968d64b2..2fa37b3b2 100644 --- a/router/router.go +++ b/router/router.go @@ -158,6 +158,10 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl session.MustAdmin(), server.ResumeQueue, ) + queue.GET("/norunningbuilds", + session.MustAdmin(), + server.BlockTilQueueHasRunningItem, + ) } auth := e.Group("/authorize") diff --git a/server/hook.go b/server/hook.go index 9f82a172d..0becc690c 100644 --- a/server/hook.go +++ b/server/hook.go @@ -62,6 +62,16 @@ func ResumeQueue(c *gin.Context) { c.Status(http.StatusOK) } +func BlockTilQueueHasRunningItem(c *gin.Context) { + for { + info := Config.Services.Queue.Info(c) + if info.Stats.Running == 0 { + break + } + } + c.Status(http.StatusOK) +} + func PostHook(c *gin.Context) { remote_ := remote.FromContext(c)