Sfoglia il codice sorgente

:gear: API: annotate online state from healthcheck

Ettore Di Giacinto 3 anni fa
parent
commit
4c1fa0290d
2 ha cambiato i file con 9 aggiunte e 0 eliminazioni
  1. 8 0
      api/api.go
  2. 1 0
      api/types/machine.go

+ 8 - 0
api/api.go

@@ -122,6 +122,9 @@ func API(ctx context.Context, l string, defaultInterval, timeout time.Duration,
 
 	ec.GET(MachineURL, func(c echo.Context) error {
 		list := []*apiTypes.Machine{}
+
+		online := services.AvailableNodes(ledger, 20*time.Minute)
+
 		for _, v := range ledger.CurrentData()[protocol.MachinesLedgerKey] {
 			machine := &types.Machine{}
 			v.Unmarshal(machine)
@@ -138,6 +141,11 @@ func API(ctx context.Context, l string, defaultInterval, timeout time.Duration,
 					m.OnChain = true
 				}
 			}
+			for _, a := range online {
+				if a == machine.PeerID {
+					m.Online = true
+				}
+			}
 			list = append(list, m)
 
 		}

+ 1 - 0
api/types/machine.go

@@ -21,4 +21,5 @@ type Machine struct {
 	types.Machine
 	Connected bool
 	OnChain   bool
+	Online    bool
 }