Add a Name to Workflow Execution

This commit is contained in:
mr 2024-08-06 08:40:05 +02:00
parent dd5f8f5b2d
commit d2484e84f0
4 changed files with 17 additions and 2 deletions

View File

@ -56,6 +56,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
} }
for s := c.Next(*realData.Schedule.Start); !s.IsZero() && s.Before(*realData.Schedule.End); s = c.Next(s) { for s := c.Next(*realData.Schedule.Start); !s.IsZero() && s.Before(*realData.Schedule.End); s = c.Next(s) {
obj := &workflow_execution.WorkflowExecution{ obj := &workflow_execution.WorkflowExecution{
AbstractObject: utils.AbstractObject{
Name: realData.Schedule.Name,
},
ExecDate: &s, ExecDate: &s,
EndDate: realData.Schedule.End, EndDate: realData.Schedule.End,
State: 1, State: 1,
@ -66,6 +69,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
} else { } else {
obj := &workflow_execution.WorkflowExecution{ obj := &workflow_execution.WorkflowExecution{
AbstractObject: utils.AbstractObject{
Name: realData.Schedule.Name,
},
ExecDate: realData.Schedule.Start, ExecDate: realData.Schedule.Start,
EndDate: realData.Schedule.End, EndDate: realData.Schedule.End,
State: 1, State: 1,

View File

@ -4,6 +4,7 @@ import "time"
type WorkflowSchedule struct { type WorkflowSchedule struct {
Id string `json:"id"` Id string `json:"id"`
Name string `json:"name" bson:"name" validate:"required"`
Start *time.Time `json:"start" bson:"start" validate:"required"` Start *time.Time `json:"start" bson:"start" validate:"required"`
End *time.Time `json:"end,omitempty" bson:"end,omitempty"` End *time.Time `json:"end,omitempty" bson:"end,omitempty"`
Cron string `json:"cron,omitempty" bson:"cron,omitempty"` Cron string `json:"cron,omitempty" bson:"cron,omitempty"`

View File

@ -38,7 +38,7 @@ func (d ScheduledType) EnumIndex() int {
} }
type WorkflowExecution struct { type WorkflowExecution struct {
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"` utils.AbstractObject
ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"`
EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"`
State int64 `json:"state,omitempty" bson:"state,omitempty"` State int64 `json:"state,omitempty" bson:"state,omitempty"`

View File

@ -53,18 +53,26 @@ func (wfa workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, in
return nil, 404, err return nil, 404, err
} }
for _, r := range results { for _, r := range results {
objs = append(objs, &r) objs = append(objs, &r.AbstractObject)
} }
return objs, 200, nil return objs, 200, nil
} }
func (wfa *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) { func (wfa *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{} objs := []utils.ShallowDBObject{}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
filters = &dbs.Filters{
Or: map[string][]dbs.Filter{
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
},
}
}
res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType()) res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType())
if err != nil { if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error()) wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err return nil, code, err
} }
var results []WorkflowExecution var results []WorkflowExecution
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err return nil, 404, err