simplify call to peer

This commit is contained in:
mr 2024-08-23 10:01:37 +02:00
parent c88b29a0ca
commit 745fc7779e

View File

@ -37,7 +37,7 @@ func (p *PeerCache) urlFormat(url string, dt utils.DataType) string {
return url
}
func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) (*Peer, bool) {
func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools.HTTPCaller) (*Peer, bool) {
api := tools.API{}
access := (&Peer{}).GetAccessor(nil)
res, code, _ := access.LoadOne(peerID)
@ -59,8 +59,7 @@ func (p *PeerCache) checkPeerStatus(peerID string, caller *tools.HTTPCaller) (*P
state, services := api.CheckRemotePeer(url)
res.(*Peer).Services = services
access.UpdateOne(res, peerID)
fmt.Printf("Peer %v is %v\n", peerID, state)
return res.(*Peer), state != tools.DEAD
return res.(*Peer), state != tools.DEAD && services[appName] == 0
}
func (p *PeerCache) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
@ -91,7 +90,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
DataType: dt.EnumIndex(),
DataID: dataID,
}
if mypeer, ok := p.checkPeerStatus(peerID, caller); !ok {
if mypeer, ok := p.checkPeerStatus(peerID, dt.API(), caller); !ok {
mypeer.AddExecution(*pexec)
mypeer.GetAccessor(nil).UpdateOne(mypeer, peerID)
return nil, errors.New("peer is not reachable")