summaryrefslogtreecommitdiff
path: root/internal/runchecks.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/runchecks.go')
-rw-r--r--internal/runchecks.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/internal/runchecks.go b/internal/runchecks.go
index 788e77d..fb7a9c4 100644
--- a/internal/runchecks.go
+++ b/internal/runchecks.go
@@ -3,6 +3,7 @@ package internal
import (
"context"
"log"
+ "math/rand"
"sync"
"time"
)
@@ -36,6 +37,25 @@ func runChecks(ctx context.Context, state state, conf config) state {
inputWg.Add(len(conf.Checks))
for check := range inputCh {
+ if age := state.age(check.name); check.RunInterval > int(age.Seconds()) {
+ lastCheckState, ok := state.checks[check.name]
+ if ok {
+ log.Printf("Skipping %s: interval not yet reached (%v (%v) <= %v)", check.name,
+ int(age.Seconds()), age, check.RunInterval)
+ outputCh <- checkResult{
+ name: check.name,
+ output: lastCheckState.output,
+ epoch: lastCheckState.Epoch,
+ status: lastCheckState.Status,
+ federated: lastCheckState.federated,
+ }
+ inputWg.Done()
+ continue
+ }
+ log.Println("Something went wrong... expected check state for", check,
+ "bug got nothing! Proceeding anyway")
+ }
+
go func(check namedCheck) {
outputCh <- runCheck(ctx, limitCh, deps, check, conf, check.Retries)
inputWg.Done()
@@ -52,14 +72,20 @@ func runChecks(ctx context.Context, state state, conf config) state {
return state
}
-func runCheck(ctx context.Context, limitCh chan struct{},
- deps dependency, check namedCheck, conf config, retries int) checkResult {
-
+func runCheck(ctx context.Context, limitCh chan struct{}, deps dependency,
+ check namedCheck, conf config, retries int,
+) checkResult {
if err := deps.wait(ctx, check.DependsOn); err != nil {
deps.notOk(check.name)
return check.skip(err.Error())
}
+ if check.RandomSpread > 0 {
+ d := time.Duration(rand.Intn(check.RandomSpread)) * time.Second
+ log.Printf("Sleeping %v before running %s", d, check.name)
+ time.Sleep(d)
+ }
+
limitCh <- struct{}{}
checkCtx, cancel := context.WithTimeout(ctx,
@@ -84,4 +110,4 @@ func runCheck(ctx context.Context, limitCh chan struct{},
<-limitCh
return checkResult
-}
+} \ No newline at end of file