Add hook to init and listen observatory statuses

This commit is contained in:
世界 2021-09-05 10:47:09 +08:00
parent 390a76ff61
commit 5bf2b31883
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
2 changed files with 18 additions and 0 deletions

View File

@ -32,6 +32,8 @@ type Observer struct {
finished *done.Instance
ohm outbound.Manager
StatusUpdate func(result *OutboundStatus)
}
func (o *Observer) GetObservation(ctx context.Context) (proto.Message, error) {
@ -183,6 +185,10 @@ func (o *Observer) updateStatusForResult(outbound string, result *ProbeResult) {
status.LastErrorReason = result.LastErrorReason
status.Delay = 99999999
}
if o.StatusUpdate != nil {
o.StatusUpdate(status)
}
}
func (o *Observer) findStatusLocationLockHolderOnly(outbound string) int {

View File

@ -0,0 +1,12 @@
package observatory
func (o *Observer) UpdateStatus(result *OutboundStatus) {
o.statusLock.Lock()
defer o.statusLock.Unlock()
if location := o.findStatusLocationLockHolderOnly(result.OutboundTag); location != -1 {
o.status[location] = result
} else {
o.status = append(o.status, result)
}
}