simplify call to peer

This commit is contained in:
mr 2024-08-27 10:07:13 +02:00
parent 0652215c18
commit 091cbb9e7f
2 changed files with 10 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import (
type SharedWorkspace struct {
utils.AbstractObject
IsSent bool `json:"is_sent" bson:"-"`
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"`
Version string `json:"version,omitempty" bson:"version,omitempty"`
Description string `json:"description,omitempty" bson:"description,omitempty" validate:"required"`

View File

@ -152,11 +152,13 @@ func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
return
}
paccess := (&peer.Peer{})
for _, v := range shared.Peers {
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() {
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() || shared.IsSent {
continue
}
shared.IsSent = true
b, err := paccess.LaunchPeerExecution(v, v, utils.SHARED_WORKSPACE, tools.POST, shared.Serialize(), wfa.Caller)
if err != nil && b == nil {
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
@ -165,11 +167,12 @@ func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
}
func (wfa *sharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
wfa.deleteToPeer(set.(*SharedWorkspace))
wfa.sharedWorkflow(set.(*SharedWorkspace), id)
wfa.sharedWorkspace(set.(*SharedWorkspace), id)
wfa.sendToPeer(set.(*SharedWorkspace))
return wfa.GenericUpdateOne(set.(*SharedWorkspace), id, wfa, &SharedWorkspace{})
res, code, err := wfa.GenericUpdateOne(set.(*SharedWorkspace), id, wfa, &SharedWorkspace{})
wfa.deleteToPeer(res.(*SharedWorkspace))
wfa.sharedWorkflow(res.(*SharedWorkspace), id)
wfa.sharedWorkspace(res.(*SharedWorkspace), id)
wfa.sendToPeer(res.(*SharedWorkspace))
return res, code, err
}
func (wfa *sharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {