correct workflow problem

This commit is contained in:
mr 2024-08-29 11:03:26 +02:00
parent a53e3c987d
commit 2e8246fb2f
2 changed files with 20 additions and 5 deletions

View File

@ -21,6 +21,9 @@ type AbstractWorkflow struct {
} }
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) { func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
if w.Graph == nil || w.Graph.Items == nil {
return false, ""
}
if d, ok := w.Graph.Items[link.Source.ID]; ok && d.Datacenter != nil { if d, ok := w.Graph.Items[link.Source.ID]; ok && d.Datacenter != nil {
return true, d.Datacenter.UUID return true, d.Datacenter.UUID
} }

View File

@ -82,7 +82,11 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
wfa.execution(id, &Workflow{ wfa.execution(id, &Workflow{
AbstractWorkflow: AbstractWorkflow{ScheduleActive: false}, AbstractWorkflow: AbstractWorkflow{ScheduleActive: false},
}, true) }, true)
return wfa.GenericDeleteOne(id, wfa) res, code, err := wfa.GenericDeleteOne(id, wfa)
if res != nil && code == 200 {
wfa.execute(res.(*Workflow), false)
}
return res, code, err
} }
func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*workflow_execution.WorkflowExecution) error { func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*workflow_execution.WorkflowExecution) error {
@ -157,6 +161,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
"workflow_id": id, "workflow_id": id,
"state": 1, "state": 1,
}, utils.WORKFLOW_EXECUTION.String()) }, utils.WORKFLOW_EXECUTION.String())
wfa.book(id, realData, []*workflow_execution.WorkflowExecution{})
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData)
} }
if len(execs) > 0 { if len(execs) > 0 {
@ -194,7 +199,7 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
return nil, code, err return nil, code, err
} }
} }
wfa.execute(res.(*Workflow)) wfa.execute(res.(*Workflow), false)
return res, code, err return res, code, err
} }
@ -212,7 +217,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)) wfa.execute(res.(*Workflow), false)
return res, code, err return res, code, err
} }
@ -220,7 +225,8 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
return wfa.GenericStoreOne(data, wfa) return wfa.GenericStoreOne(data, wfa)
} }
func (wfa *workflowMongoAccessor) execute(workflow *Workflow) { func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
accessor := (&workspace.Workspace{}).GetAccessor(nil) accessor := (&workspace.Workspace{}).GetAccessor(nil)
filters := &dbs.Filters{ filters := &dbs.Filters{
Or: map[string][]dbs.Filter{ Or: map[string][]dbs.Filter{
@ -228,6 +234,12 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow) {
}, },
} }
resource, _, err := accessor.Search(filters, "") resource, _, err := accessor.Search(filters, "")
if delete {
for _, r := range resource {
accessor.DeleteOne(r.GetID())
}
return
}
if err == nil && len(resource) > 0 { if err == nil && len(resource) > 0 {
accessor.UpdateOne(&workspace.Workspace{ accessor.UpdateOne(&workspace.Workspace{
Active: true, Active: true,
@ -262,7 +274,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) wfa.execute(&workflow, false)
return &workflow, 200, nil return &workflow, 200, nil
} }