From 06c3af5d4d61184267c0fb9507401e4ee7a20fde Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 12 Nov 2024 15:10:26 +0100 Subject: [PATCH] state execution --- models/booking/booking_mongo_accessor.go | 10 +++++++++- .../workflow_execution_mongo_accessor.go | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/models/booking/booking_mongo_accessor.go b/models/booking/booking_mongo_accessor.go index 7625fe7..e41c770 100644 --- a/models/booking/booking_mongo_accessor.go +++ b/models/booking/booking_mongo_accessor.go @@ -52,7 +52,7 @@ func (wfa *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) return &workflow, 200, nil } -func (wfa bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { +func (wfa *bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { objs := []utils.ShallowDBObject{} res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType()) if err != nil { @@ -64,6 +64,10 @@ func (wfa bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) return nil, 404, err } for _, r := range results { + if r.State == workflow_execution.SCHEDULED && time.Now().UTC().After(*r.ExecDate) { + r.State = workflow_execution.FORGOTTEN + wfa.GenericRawUpdateOne(&r, r.UUID, wfa) + } objs = append(objs, &r.AbstractObject) // Warning only AbstractObject is returned } return objs, 200, nil @@ -89,6 +93,10 @@ func (wfa *bookingMongoAccessor) Search(filters *dbs.Filters, search string) ([] return nil, 404, err } for _, r := range results { + if r.State == workflow_execution.SCHEDULED && time.Now().UTC().After(*r.ExecDate) { + r.State = workflow_execution.FORGOTTEN + wfa.GenericRawUpdateOne(&r, r.UUID, wfa) + } objs = append(objs, &r) } return objs, 200, nil diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index 5a77255..4ac365b 100644 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -47,7 +47,7 @@ func (wfa *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, i return &workflow, 200, nil } -func (wfa workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { +func (wfa *workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { objs := []utils.ShallowDBObject{} res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType()) if err != nil { @@ -59,6 +59,10 @@ func (wfa workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, in return nil, 404, err } for _, r := range results { + if r.State == SCHEDULED && time.Now().UTC().After(*r.ExecDate) { + r.State = FORGOTTEN + wfa.GenericRawUpdateOne(&r, r.UUID, wfa) + } objs = append(objs, &r.AbstractObject) } return objs, 200, nil @@ -84,6 +88,10 @@ func (wfa *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search s return nil, 404, err } for _, r := range results { + if r.State == SCHEDULED && time.Now().UTC().After(*r.ExecDate) { + r.State = FORGOTTEN + wfa.GenericRawUpdateOne(&r, r.UUID, wfa) + } objs = append(objs, &r) } return objs, 200, nil