2020-07-03 13:52:04 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/service"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/state"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (n *neofsObject) statusHealth(ctx context.Context) bool {
|
|
|
|
req := new(state.HealthRequest)
|
|
|
|
req.SetTTL(service.NonForwardingTTL)
|
|
|
|
req.SetVersion(APIVersion)
|
|
|
|
|
2020-07-03 14:12:30 +00:00
|
|
|
err := service.SignRequestData(n.key, req)
|
2020-07-03 13:52:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
conn, err := n.cli.GetConnection(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1 second timeout is the same as in gateway-common.go
|
|
|
|
// see: cmd/gateway-common.go:295
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
res, err := state.NewStatusClient(conn).HealthCheck(ctx, req)
|
|
|
|
|
|
|
|
return err != nil && res != nil && res.Healthy
|
|
|
|
}
|