Skip to content

Commit ed4a84f

Browse files
committed
chore: bit hacky health handler
1 parent de72fd5 commit ed4a84f

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

cmd/serve.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ to interact and monitor the Scroll Application`,
161161
if currentScroll.CanColdStart() {
162162

163163
for {
164+
healthHandler.Started = false
164165
logger.Log().Info("Starting coldstarter")
165166
finish := coldStarter.Start(ctx)
166167
executedPort := <-finish
@@ -171,7 +172,7 @@ to interact and monitor the Scroll Application`,
171172

172173
logger.Log().Info("Coldstarter done, starting scroll")
173174

174-
startup(scrollService, processLauncher, queueManager, portService, coldStarter, cwd, doneChan)
175+
startup(scrollService, processLauncher, queueManager, portService, coldStarter, healthHandler, cwd, doneChan)
175176

176177
portService.ResetOpenPorts()
177178

@@ -211,10 +212,10 @@ to interact and monitor the Scroll Application`,
211212
}
212213
} else {
213214
logger.Log().Warn("No ports to start, skipping coldstarter")
214-
startup(scrollService, processLauncher, queueManager, portService, coldStarter, cwd, doneChan)
215+
startup(scrollService, processLauncher, queueManager, portService, coldStarter, healthHandler, cwd, doneChan)
215216
}
216217
} else {
217-
startup(scrollService, processLauncher, queueManager, portService, coldStarter, cwd, doneChan)
218+
startup(scrollService, processLauncher, queueManager, portService, coldStarter, healthHandler, cwd, doneChan)
218219
}
219220

220221
}()
@@ -264,7 +265,9 @@ func init() {
264265
ServeCommand.Flags().UintVarP(&maxStartupHealthCheckTimeout, "max-health-check-startup-timeount", "", 0, "Sets the max amount of time the health check is allowed to take on startup. If the value is 0, there will be no timeout. This is useful to prevent the health check from blocking the startup of the daemon fully.")
265266
}
266267

267-
func startup(scrollService *services.ScrollService, processLauncher *services.ProcedureLauncher, queueManager *services.QueueManager, portSerivce *services.PortMonitor, coldStarter *services.ColdStarter, cwd string, doneChan chan error) {
268+
func startup(scrollService *services.ScrollService, processLauncher *services.ProcedureLauncher, queueManager *services.QueueManager, portSerivce *services.PortMonitor, coldStarter *services.ColdStarter, healthHandler *handler.HealthHandler, cwd string, doneChan chan error) {
269+
270+
healthHandler.Started = true
268271

269272
currentScroll := scrollService.GetCurrent()
270273

internal/handler/health_handler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
type HealthHandler struct {
1111
portService ports.PortServiceInterface
1212
timeoutDone bool
13+
Started bool
1314
}
1415

1516
func NewHealthHandler(
@@ -20,6 +21,7 @@ func NewHealthHandler(
2021
h := &HealthHandler{
2122
portService,
2223
false,
24+
false,
2325
}
2426

2527
// if timeoutSec == 0, we want at some point to not show a bad health status
@@ -48,7 +50,9 @@ func (p *HealthHandler) Health(c *fiber.Ctx) error {
4850
return c.SendString("Manditory ports are not open")
4951

5052
}
51-
53+
if !p.Started {
54+
return c.SendString("idle")
55+
}
5256
return c.SendString("ok")
5357
}
5458

0 commit comments

Comments
 (0)