Explorar el Código

Add hook to init and listen observatory statuses

世界 hace 4 años
padre
commit
5bf2b31883
Se han modificado 2 ficheros con 18 adiciones y 0 borrados
  1. 6 0
      app/observatory/observer.go
  2. 12 0
      app/observatory/persist.go

+ 6 - 0
app/observatory/observer.go

@@ -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 {

+ 12 - 0
app/observatory/persist.go

@@ -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)
+	}
+}