simplify call to peer
This commit is contained in:
parent
5b3779e4cb
commit
1986143dd0
@ -59,6 +59,7 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
||||
state, services := api.CheckRemotePeer(url)
|
||||
res.(*Peer).Services = services
|
||||
access.UpdateOne(res, peerID)
|
||||
fmt.Println("PEER AFT 6", state, services, appName)
|
||||
return res.(*Peer), state != tools.DEAD && services[appName] == 0
|
||||
}
|
||||
|
||||
|
12
tools/api.go
12
tools/api.go
@ -84,6 +84,9 @@ func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string,
|
||||
// Check if the database is up
|
||||
new := map[string]string{}
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{})
|
||||
code := 0
|
||||
u := ""
|
||||
e := ""
|
||||
for appName, url := range urls {
|
||||
var resp APIStatusResponse
|
||||
b, err := caller.CallGet(url, "/version/status")
|
||||
@ -95,10 +98,15 @@ func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string,
|
||||
return DEAD, new, errors.New(url + " -> is DEAD")
|
||||
}
|
||||
new[appName] = resp.Data.State
|
||||
if resp.Data.Code != 0 {
|
||||
return REDUCED_SERVICE, new, errors.New(url + " -> " + resp.Error)
|
||||
if resp.Data.Code > code {
|
||||
code = resp.Data.Code
|
||||
u = url
|
||||
e += resp.Error
|
||||
}
|
||||
}
|
||||
if code > 0 {
|
||||
return REDUCED_SERVICE, new, errors.New(u + " -> " + e)
|
||||
}
|
||||
return ALIVE, new, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user