From 55d3657958b62e1dd6f892f29a659a188c889117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Wed, 25 Oct 2023 12:52:46 +0200 Subject: [PATCH] feat(torch): comment code - rename var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon MaƱes --- pkg/nodes/queue.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/nodes/queue.go b/pkg/nodes/queue.go index 95c82eb..0e85de4 100644 --- a/pkg/nodes/queue.go +++ b/pkg/nodes/queue.go @@ -46,22 +46,27 @@ func processQueue() { } } +// CheckNodesInDBOrCreateThem try to find the node in the DB, if the node is not in the DB, it tries to create it. func CheckNodesInDBOrCreateThem(peer config.Peer, red *redis.RedisClient, ctx context.Context) { log.Info("Processing Node in the queue: ", "[", peer.NodeName, "]") // check if the node is in the DB - c, err := redis.CheckIfNodeExistsInDB(red, ctx, peer.NodeName) + ma, err := redis.CheckIfNodeExistsInDB(red, ctx, peer.NodeName) if err != nil { log.Error("Error CheckIfNodeExistsInDB for node: [", peer.NodeName, "]", err) } + // if the node doesn't exist in the DB, let's try to create it - if c == "" { + if ma == "" { log.Info("Node ", "["+peer.NodeName+"]"+" NOT found in DB, let's try to generate it") - c, err = GenerateNodeIdAndSaveIt(peer, peer.NodeName, red, ctx) + ma, err = GenerateNodeIdAndSaveIt(peer, peer.NodeName, red, ctx) if err != nil { log.Error("Error GenerateNodeIdAndSaveIt for full-node: [", peer.NodeName, "]", err) } } - if c == "" { + + // check if the multiaddress is empty after trying to generate it + if ma == "" { + // check if the node is still under the maximum number of retries if peer.RetryCount < MaxRetryCount { log.Info("Node ", "["+peer.NodeName+"]"+" NOT found in DB, adding it to the queue, attempt: ", "[", peer.RetryCount, "]") peer.RetryCount++ // increment the counter @@ -70,12 +75,12 @@ func CheckNodesInDBOrCreateThem(peer config.Peer, red *redis.RedisClient, ctx co log.Info("Max retry count reached for node: ", "[", peer.NodeName, "]", "it might have some issues...") } } else { - log.Info("Node ", "[", peer.NodeName, "]", " found in DB, ID: ", "[", c, "]") + log.Info("Node ", "[", peer.NodeName, "]", " found in DB, ID: ", "[", ma, "]") // Register a multi-address metric m := metrics.MultiAddrs{ ServiceName: "torch", NodeName: peer.NodeName, - MultiAddr: c, + MultiAddr: ma, Namespace: k8s.GetCurrentNamespace(), Value: 1, }