Skip to content

Commit 9117c56

Browse files
committed
xally: check if nodes data stale, version: bump to 1.1.3
1 parent 0cfdd4f commit 9117c56

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

services/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"time"
1313
)
1414

15-
const version = "1.1.2"
15+
const version = "1.1.3"
1616

1717
type Config struct {
1818
Node string `json:"node"`

services/xally/xally.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const baseURL = "https://api-node.xally.ai"
1818
const levelPath = "/root/.config/xally_client/Local Storage/leveldb/000003.log"
1919

2020
var (
21-
lock sync.Mutex
21+
lock sync.Mutex
22+
nodeData []NodeInfo
23+
previousData []NodeInfo
2224
)
2325

2426
type ApiResponse struct {
@@ -37,8 +39,6 @@ type NodeInfo struct {
3739
LastCheckTS int64 `json:"last_check_ts"`
3840
}
3941

40-
var nodeData []NodeInfo
41-
4242
func FetchNodeData() ([]NodeInfo, error) {
4343
lock.Lock()
4444
defer lock.Unlock()
@@ -100,6 +100,7 @@ func FetchNodeData() ([]NodeInfo, error) {
100100
nodes[i].LastCheckTS = lastCheckTs
101101
}
102102

103+
previousData = nodeData
103104
nodeData = nodes
104105

105106
return nodes, nil
@@ -123,6 +124,26 @@ func CheckRunning(config *config.Config) {
123124
}
124125
}
125126

127+
previousDataMap := make(map[string]NodeInfo)
128+
for _, node := range previousData {
129+
previousDataMap[node.NodeID] = node
130+
}
131+
132+
var unchangedNodes []string
133+
134+
for _, node := range nodes {
135+
if prevNode, ok := previousDataMap[node.NodeID]; ok {
136+
if node.RunningTime == prevNode.RunningTime && node.Point == prevNode.Point {
137+
unchangedNodes = append(unchangedNodes, node.NodeID)
138+
}
139+
}
140+
}
141+
142+
if len(unchangedNodes) > 0 {
143+
logger.Error("Nodes have not changed: ", unchangedNodes)
144+
allGood = false
145+
}
146+
126147
if !allGood {
127148
timestamp := time.Now().UTC().Format("2006-01-02 15:04:05")
128149
message := "-----------------------------------------------------------------------\n"

0 commit comments

Comments
 (0)