keep mq updates in a single go func

This commit is contained in:
Abhishek Kondur 2023-07-10 16:56:03 +05:30
parent 3f11ddd8c5
commit 504ce7feb9

View file

@ -258,13 +258,14 @@ func addHostToNetwork(w http.ResponseWriter, r *http.Request) {
return
}
logger.Log(1, "added new node", newNode.ID.String(), "to host", currHost.Name)
mq.HostUpdate(&models.HostUpdate{
Action: models.JoinHostToNetwork,
Host: *currHost,
Node: *newNode,
})
go mq.PublishPeerUpdate()
go func() {
mq.HostUpdate(&models.HostUpdate{
Action: models.JoinHostToNetwork,
Host: *currHost,
Node: *newNode,
})
mq.PublishPeerUpdate()
}()
logger.Log(2, r.Header.Get("user"), fmt.Sprintf("added host %s to network %s", currHost.Name, network))
w.WriteHeader(http.StatusOK)
}