Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

healthcheck function only executed once? #22

Open
KEZHwMlXV1vFzs6QvY8v5WjX5 opened this issue Feb 12, 2019 · 1 comment
Open

healthcheck function only executed once? #22

KEZHwMlXV1vFzs6QvY8v5WjX5 opened this issue Feb 12, 2019 · 1 comment

Comments

@KEZHwMlXV1vFzs6QvY8v5WjX5

Hi,
trying to get this little example to run but it does not seem to even execute the mycheck function more than once during the startup. I thought it should be happening every time I try to access the /live endpoint?

package main

import (
	"errors"
	"fmt"
	h "github.com/heptiolabs/healthcheck"
	"math/rand"
	"net/http"
)

func main() {
	Example()
}

func Example() {
	health := h.NewHandler()
	health.AddLivenessCheck("mycheck", mycheck())
	http.ListenAndServe("0.0.0.0:8080", health)
}

func mycheck() h.Check {
	if rand.Intn(2) == 1 {
		return func() error {
			return nil
		}
	} else {
		return func() error {
			return errors.New("0")
		}
	}
}
@nmnellis
Copy link

you are only returning one of the funcs at runtime, so itll always just be that one.

here is the fix

func mycheck() h.Check {
  return func() error{
	if rand.Intn(2) == 1 {
	  return nil
	} else {
	  return errors.New("0")
	}
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants