This commit is contained in:
mr 2024-09-23 16:15:40 +02:00
parent 50ea0969e6
commit 95a4acff36

View File

@ -96,7 +96,7 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
}, true) // delete the executions }, true) // delete the executions
res, code, err := wfa.GenericDeleteOne(id, wfa) res, code, err := wfa.GenericDeleteOne(id, wfa)
if res != nil && code == 200 { if res != nil && code == 200 {
wfa.execute(res.(*Workflow), false) // up to date the workspace for the workflow wfa.execute(res.(*Workflow), false, false) // up to date the workspace for the workflow
} }
wfa.share(res.(*Workflow), true, wfa.Caller) // send the deletion to the peers where workflow is shared wfa.share(res.(*Workflow), true, wfa.Caller) // send the deletion to the peers where workflow is shared
return res, code, err return res, code, err
@ -255,7 +255,7 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
return nil, code, errors.New("could not update the executions : " + err.Error()) return nil, code, errors.New("could not update the executions : " + err.Error())
} }
} }
wfa.execute(res.(*Workflow), false) // update the workspace for the workflow wfa.execute(res.(*Workflow), false, false) // update the workspace for the workflow
wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers
return res, code, nil return res, code, nil
} }
@ -271,7 +271,7 @@ func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil { if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil {
return nil, code, err return nil, code, err
} }
wfa.execute(res.(*Workflow), false) // store the workspace for the workflow wfa.execute(res.(*Workflow), false, false) // store the workspace for the workflow
return res, code, nil return res, code, nil
} }
@ -282,7 +282,7 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
// execute is a function that executes a workflow // execute is a function that executes a workflow
// it stores the workflow resources in a specific workspace to never have a conflict in UI and logic // it stores the workflow resources in a specific workspace to never have a conflict in UI and logic
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) { func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active bool) {
accessor := (&workspace.Workspace{}).GetAccessor(nil) accessor := (&workspace.Workspace{}).GetAccessor(nil)
filters := &dbs.Filters{ filters := &dbs.Filters{
@ -299,7 +299,7 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
} }
if err == nil && len(resource) > 0 { // if the workspace already exists, update it if err == nil && len(resource) > 0 { // if the workspace already exists, update it
accessor.UpdateOne(&workspace.Workspace{ accessor.UpdateOne(&workspace.Workspace{
Active: true, Active: active,
ResourceSet: resources.ResourceSet{ ResourceSet: resources.ResourceSet{
Datas: workflow.Datas, Datas: workflow.Datas,
Processings: workflow.Processings, Processings: workflow.Processings,
@ -310,7 +310,7 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
}, resource[0].GetID()) }, resource[0].GetID())
} else { // if the workspace does not exist, create it } else { // if the workspace does not exist, create it
accessor.StoreOne(&workspace.Workspace{ accessor.StoreOne(&workspace.Workspace{
Active: true, Active: active,
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"}, AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
ResourceSet: resources.ResourceSet{ ResourceSet: resources.ResourceSet{
Datas: workflow.Datas, Datas: workflow.Datas,
@ -332,7 +332,7 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
return nil, code, err return nil, code, err
} }
res_mongo.Decode(&workflow) res_mongo.Decode(&workflow)
wfa.execute(&workflow, false) // if no workspace is attached to the workflow, create it wfa.execute(&workflow, false, true) // if no workspace is attached to the workflow, create it
return &workflow, 200, nil return &workflow, 200, nil
} }