mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
client: add StatusExporter in service (#4182)
This commit is contained in:
parent
c1893ee1b4
commit
405969085f
@ -380,18 +380,31 @@ func (svr *Service) stop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(fatedier): Use StatusExporter to provide query interfaces instead of directly using methods from the Service.
|
func (svr *Service) getProxyStatus(name string) (*proxy.WorkingStatus, bool) {
|
||||||
func (svr *Service) GetProxyStatus(name string) (*proxy.WorkingStatus, error) {
|
|
||||||
svr.ctlMu.RLock()
|
svr.ctlMu.RLock()
|
||||||
ctl := svr.ctl
|
ctl := svr.ctl
|
||||||
svr.ctlMu.RUnlock()
|
svr.ctlMu.RUnlock()
|
||||||
|
|
||||||
if ctl == nil {
|
if ctl == nil {
|
||||||
return nil, fmt.Errorf("control is not running")
|
return nil, false
|
||||||
}
|
}
|
||||||
ws, ok := ctl.pm.GetProxyStatus(name)
|
return ctl.pm.GetProxyStatus(name)
|
||||||
if !ok {
|
}
|
||||||
return nil, fmt.Errorf("proxy [%s] is not found", name)
|
|
||||||
}
|
func (svr *Service) StatusExporter() StatusExporter {
|
||||||
return ws, nil
|
return &statusExporterImpl{
|
||||||
|
getProxyStatusFunc: svr.getProxyStatus,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusExporter interface {
|
||||||
|
GetProxyStatus(name string) (*proxy.WorkingStatus, bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
type statusExporterImpl struct {
|
||||||
|
getProxyStatusFunc func(name string) (*proxy.WorkingStatus, bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *statusExporterImpl) GetProxyStatus(name string) (*proxy.WorkingStatus, bool) {
|
||||||
|
return s.getProxyStatusFunc(name)
|
||||||
}
|
}
|
||||||
|
@ -363,11 +363,13 @@ func (s *TunnelServer) waitProxyStatusReady(name string, timeout time.Duration)
|
|||||||
timer := time.NewTimer(timeout)
|
timer := time.NewTimer(timeout)
|
||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
|
|
||||||
|
statusExporter := s.vc.Service().StatusExporter()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
ps, err := s.vc.Service().GetProxyStatus(name)
|
ps, ok := statusExporter.GetProxyStatus(name)
|
||||||
if err != nil {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch ps.Phase {
|
switch ps.Phase {
|
||||||
|
Loading…
Reference in New Issue
Block a user