NATS is an OCLIB tool

This commit is contained in:
mr
2024-08-21 10:04:09 +02:00
parent e31815f576
commit 649a1098c3
6 changed files with 89 additions and 18 deletions

View File

@@ -138,28 +138,22 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
}
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
if realData.Schedule == nil && realData.ScheduleActive {
res, code, err := wfa.LoadOne(id)
if code == 200 {
r := res.(*Workflow)
if r.Schedule != nil {
err = wfa.book(id, r, []*workflow_execution.WorkflowExecution{})
}
}
return 200, err
var err error
nats := tools.NATSCaller{}
res, code, _ := wfa.LoadOne(id)
if code != 200 {
return 404, errors.New("could not load workflow")
}
if realData.Schedule == nil && !realData.ScheduleActive {
if (realData.Schedule == nil && !realData.ScheduleActive) || (realData.Schedule == nil && realData.ScheduleActive) {
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
"state": 1,
"workflow_id": id,
}, utils.WORKFLOW_EXECUTION.String())
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{})
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData)
return 200, err
}
res, code, _ := wfa.LoadOne(id)
if code != 200 {
return 404, errors.New("could not load workflow")
}
r := res.(*Workflow)
if r.Schedule != nil && r.Schedule.Start == realData.Schedule.Start && r.Schedule.End == realData.Schedule.End && r.Schedule.Cron == realData.Schedule.Cron {
return 200, nil
@@ -178,6 +172,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
"workflow_id": id,
"state": 1,
}, utils.WORKFLOW_EXECUTION.String())
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData)
}
if len(execs) > 0 {
for _, obj := range execs {
@@ -186,6 +181,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
return code, err
}
}
nats.SetNATSPub(utils.WORKFLOW.String(), tools.CREATE, realData)
} else {
return 422, err
}