mirror of
https://github.com/openfaas/faas.git
synced 2025-06-08 16:26:47 +00:00
Introduces a single-flight call to a function's health endpoint to verify that it is registered with an Istio sidecar (Envoy) before letting the invocation through. Results are cached for 5 seconds, before a probe is required again. Tested without Istio, with probe_functions environment variable set to true, I saw a probe execute in the logs. Fixes: #1721 for Istio users. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
26 lines
400 B
Go
26 lines
400 B
Go
package types
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
type routine func(attempt int) error
|
|
|
|
func Retry(r routine, label string, attempts int, interval time.Duration) error {
|
|
var err error
|
|
|
|
for i := 0; i < attempts; i++ {
|
|
res := r(i)
|
|
if res != nil {
|
|
err = res
|
|
log.Printf("[%s]: %d/%d, error: %s\n", label, i, attempts, res)
|
|
} else {
|
|
err = nil
|
|
break
|
|
}
|
|
time.Sleep(interval)
|
|
}
|
|
return err
|
|
}
|