Skip to content

Commit

Permalink
xally: check if nodes data stale, version: bump to 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hayzamjs committed May 13, 2024
1 parent 0cfdd4f commit 9117c56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion services/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"
)

const version = "1.1.2"
const version = "1.1.3"

type Config struct {
Node string `json:"node"`
Expand Down
27 changes: 24 additions & 3 deletions services/xally/xally.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const baseURL = "https://api-node.xally.ai"
const levelPath = "/root/.config/xally_client/Local Storage/leveldb/000003.log"

var (
lock sync.Mutex
lock sync.Mutex
nodeData []NodeInfo
previousData []NodeInfo
)

type ApiResponse struct {
Expand All @@ -37,8 +39,6 @@ type NodeInfo struct {
LastCheckTS int64 `json:"last_check_ts"`
}

var nodeData []NodeInfo

func FetchNodeData() ([]NodeInfo, error) {
lock.Lock()
defer lock.Unlock()
Expand Down Expand Up @@ -100,6 +100,7 @@ func FetchNodeData() ([]NodeInfo, error) {
nodes[i].LastCheckTS = lastCheckTs
}

previousData = nodeData
nodeData = nodes

return nodes, nil
Expand All @@ -123,6 +124,26 @@ func CheckRunning(config *config.Config) {
}
}

previousDataMap := make(map[string]NodeInfo)
for _, node := range previousData {
previousDataMap[node.NodeID] = node
}

var unchangedNodes []string

for _, node := range nodes {
if prevNode, ok := previousDataMap[node.NodeID]; ok {
if node.RunningTime == prevNode.RunningTime && node.Point == prevNode.Point {
unchangedNodes = append(unchangedNodes, node.NodeID)
}
}
}

if len(unchangedNodes) > 0 {
logger.Error("Nodes have not changed: ", unchangedNodes)
allGood = false
}

if !allGood {
timestamp := time.Now().UTC().Format("2006-01-02 15:04:05")
message := "-----------------------------------------------------------------------\n"
Expand Down

0 comments on commit 9117c56

Please sign in to comment.