From 4de845a828753840066f5309fbab8cfd12485ff9 Mon Sep 17 00:00:00 2001 From: Brendan Playford <34052452+teslashibe@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:03:51 -0400 Subject: [PATCH] fix: duplication of getEligibleWorkers func --- pkg/workers/send_work.go | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/pkg/workers/send_work.go b/pkg/workers/send_work.go index d50f2227..0cf51bd9 100644 --- a/pkg/workers/send_work.go +++ b/pkg/workers/send_work.go @@ -7,7 +7,6 @@ import ( masa "github.com/masa-finance/masa-oracle/pkg" "github.com/masa-finance/masa-oracle/pkg/pubsub" "github.com/masa-finance/masa-oracle/pkg/workers/messages" - "github.com/multiformats/go-multiaddr" "github.com/asynkron/protoactor-go/actor" @@ -41,7 +40,7 @@ func SendWork(node *masa.OracleNode, m *pubsub2.Message) { responseCollector := make(chan *pubsub2.Message, 1) - eligibleWorkers := getEligibleWorkers(node, message) + eligibleWorkers := GetEligibleWorkers(node, message) for retries := 0; retries < workerConfig.MaxRetries; retries++ { success := tryWorkersRoundRobin(node, eligibleWorkers, message, responseCollector) @@ -109,27 +108,6 @@ func createWorkMessage(m *pubsub2.Message, pid *actor.PID) *messages.Work { } } -func getEligibleWorkers(node *masa.OracleNode, message *messages.Work) []Worker { - var workers []Worker - - if node.IsStaked && node.IsWorker() { - workers = append(workers, Worker{IsLocal: true, NodeData: pubsub.NodeData{PeerId: node.Host.ID()}}) - } - - peers := node.NodeTracker.GetAllNodeData() - for _, p := range peers { - if isEligibleRemoteWorker(p, node, message) { - for _, addr := range p.Multiaddrs { - ipAddr, _ := addr.ValueForProtocol(multiaddr.P_IP4) - workers = append(workers, Worker{IsLocal: false, NodeData: p, IPAddr: ipAddr}) - break - } - } - } - - return workers -} - func handleLocalWorker(node *masa.OracleNode, pid *actor.PID, message *messages.Work, responseCollector chan<- *pubsub2.Message) { logrus.Info("Sending work to local worker") future := node.ActorEngine.RequestFuture(pid, message, workerConfig.WorkerTimeout)