Skip to content

Commit

Permalink
fix: duplication of getEligibleWorkers func
Browse files Browse the repository at this point in the history
  • Loading branch information
teslashibe committed Aug 6, 2024
1 parent 3d6ed60 commit 4de845a
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions pkg/workers/send_work.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4de845a

Please sign in to comment.