From b4b85046fef253d28f8e90ad76dca2e7552fe0ab Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 25 Apr 2023 00:16:39 +0300 Subject: add DependsOn --- internal/runchecks.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'internal/runchecks.go') diff --git a/internal/runchecks.go b/internal/runchecks.go index 360a1b5..48a80e8 100644 --- a/internal/runchecks.go +++ b/internal/runchecks.go @@ -11,6 +11,7 @@ func runChecks(globalCtx context.Context, state state, config config) state { limiterCh := make(chan struct{}, config.CheckConcurrency) inputCh := make(chan namedCheck) outputCh := make(chan checkResult) + deps := newDependency(config) go func() { for name, check := range config.Checks { @@ -34,17 +35,30 @@ func runChecks(globalCtx context.Context, state state, config config) state { for check := range inputCh { go func(check namedCheck) { + defer inputWg.Done() + + if err := deps.wait(globalCtx, check.DependsOn); err != nil { + deps.notOk(check.name) + outputCh <- check.skip(err.Error()) + return + } + limiterCh <- struct{}{} - defer func() { - <-limiterCh - inputWg.Done() - }() + defer func() { <-limiterCh }() ctx, cancel := context.WithTimeout(globalCtx, time.Duration(config.CheckTimeoutS)*time.Second) defer cancel() - outputCh <- check.run(ctx) + checkResult := check.run(ctx) + + if checkResult.status == critical { + deps.notOk(check.name) + } else { + deps.ok(check.name) + } + + outputCh <- checkResult }(check) } -- cgit v1.2.3