refactor: more obviously handle all target states in reporting
This commit is contained in:
1 parent
b8b3e6f9cd
commit
e3182624fd
1 file changed
+20
-13
+20
-13
@@ -174,22 +174,29 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
|
||||
}
|
||||
for address, target := range cm.targets {
|
||||
var state, info string
|
||||
switch {
|
||||
case target.state == TargetConnected:
|
||||
switch target.state {
|
||||
case TargetConnected:
|
||||
continue
|
||||
case target.lastError == nil:
|
||||
state = "connecting"
|
||||
info = ""
|
||||
case target.state == TargetAttempting:
|
||||
state = "retrying"
|
||||
info = target.lastError.Error()
|
||||
default:
|
||||
state = "failed"
|
||||
retry := "never"
|
||||
case TargetAttempting:
|
||||
if target.lastError == nil {
|
||||
state = "connecting"
|
||||
info = ""
|
||||
} else {
|
||||
state = "retrying"
|
||||
info = target.lastError.Error()
|
||||
}
|
||||
case TargetWaiting:
|
||||
until := "never"
|
||||
if !target.tryAfter.IsZero() {
|
||||
retry = target.tryAfter.String()
|
||||
until = target.tryAfter.String()
|
||||
}
|
||||
if target.lastError == nil { // shouldn't happen
|
||||
state = "waiting"
|
||||
info = "until: " + until
|
||||
} else {
|
||||
state = "failed"
|
||||
info = target.lastError.Error() + ", retry: " + until
|
||||
}
|
||||
info = target.lastError.Error() + ", retry: " + retry
|
||||
}
|
||||
slice = append(slice, LocalConnectionStatus{address, true, state, info})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user