From 241c6a5a0861644c44488f20e24064230dc0b82d Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 19 Feb 2025 08:55:11 +0100 Subject: [PATCH] casual debug, time added before change of state bookin & exec --- models/booking/booking_mongo_accessor.go | 12 ++++++++---- models/workflow/workflow_mongo_accessor.go | 2 +- .../workflow_execution_mongo_accessor.go | 12 ++++++++---- models/workspace/workspace_mongo_accessor.go | 4 +++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/models/booking/booking_mongo_accessor.go b/models/booking/booking_mongo_accessor.go index ca47f7a..18ab5f7 100644 --- a/models/booking/booking_mongo_accessor.go +++ b/models/booking/booking_mongo_accessor.go @@ -51,13 +51,15 @@ func (a *bookingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int func (a *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) { - if d.(*Booking).State == enum.DRAFT && time.Now().UTC().After(d.(*Booking).ExpectedStartDate) { + now := time.Now() + now = now.Add(time.Second * 60) + if d.(*Booking).State == enum.DRAFT && now.UTC().After(d.(*Booking).ExpectedStartDate) { return utils.GenericDeleteOne(d.GetID(), a) } if (d.(*Booking).ExpectedEndDate) == nil { d.(*Booking).State = enum.FORGOTTEN utils.GenericRawUpdateOne(d, id, a) - } else if d.(*Booking).State == enum.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) { + } else if d.(*Booking).State == enum.SCHEDULED && now.UTC().After(d.(*Booking).ExpectedStartDate) { d.(*Booking).State = enum.DELAYED utils.GenericRawUpdateOne(d, id, a) } @@ -75,11 +77,13 @@ func (a *bookingMongoAccessor) Search(filters *dbs.Filters, search string, isDra func (a *bookingMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject { return func(d utils.DBObject) utils.ShallowDBObject { - if d.(*Booking).State == enum.DRAFT && time.Now().UTC().After(d.(*Booking).ExpectedStartDate) { + now := time.Now() + now = now.Add(time.Second * 60) + if d.(*Booking).State == enum.DRAFT && now.UTC().After(d.(*Booking).ExpectedStartDate) { utils.GenericDeleteOne(d.GetID(), a) return nil } - if d.(*Booking).State == enum.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) { + if d.(*Booking).State == enum.SCHEDULED && now.UTC().After(d.(*Booking).ExpectedStartDate) { d.(*Booking).State = enum.DELAYED utils.GenericRawUpdateOne(d, d.GetID(), a) } diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index 647d29f..553acbd 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -95,7 +95,7 @@ func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils. if set.(*Workflow).Graph != nil && set.(*Workflow).Graph.Partial { return nil, 403, errors.New("you are not allowed to update a partial workflow") } - res, code, err := utils.GenericUpdateOne(a.verifyResource(set), id, a, &Workflow{}) + res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{}) if code != 200 { return nil, code, err } diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index af649d0..9bd6ec8 100644 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -60,11 +60,13 @@ func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.D func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { return utils.GenericLoadOne[*WorkflowExecution](id, func(d utils.DBObject) (utils.DBObject, int, error) { - if d.(*WorkflowExecution).State == enum.DRAFT && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) { + now := time.Now() + now = now.Add(time.Second * 60) + if d.(*WorkflowExecution).State == enum.DRAFT && !a.shallow && now.UTC().After(d.(*WorkflowExecution).ExecDate) { utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request)) return nil, 404, errors.New("not found") } - if d.(*WorkflowExecution).State == enum.SCHEDULED && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) { + if d.(*WorkflowExecution).State == enum.SCHEDULED && !a.shallow && now.UTC().After(d.(*WorkflowExecution).ExecDate) { d.(*WorkflowExecution).State = enum.FORGOTTEN utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request)) } @@ -82,11 +84,13 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject { return func(d utils.DBObject) utils.ShallowDBObject { - if d.(*WorkflowExecution).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) { + now := time.Now() + now = now.Add(time.Second * 60) + if d.(*WorkflowExecution).State == enum.DRAFT && now.UTC().After(d.(*WorkflowExecution).ExecDate) { utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request)) return nil } - if d.(*WorkflowExecution).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) { + if d.(*WorkflowExecution).State == enum.SCHEDULED && now.UTC().After(d.(*WorkflowExecution).ExecDate) { d.(*WorkflowExecution).State = enum.FORGOTTEN utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request)) return d diff --git a/models/workspace/workspace_mongo_accessor.go b/models/workspace/workspace_mongo_accessor.go index 9d46842..7711f00 100644 --- a/models/workspace/workspace_mongo_accessor.go +++ b/models/workspace/workspace_mongo_accessor.go @@ -72,9 +72,11 @@ func (a *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils func (a *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) { filters := &dbs.Filters{ Or: map[string][]dbs.Filter{ - "abstractobject.name": {{Operator: dbs.LIKE.String(), Value: data.GetName() + "_workspace"}}, + "abstractobject.name": {{Operator: dbs.LIKE.String(), Value: data.GetName() + "_workspace"}}, + "abstractobject.creator_id": {{Operator: dbs.EQUAL.String(), Value: a.GetPeerID()}}, }, } + // filters *dbs.Filters, word string, isDraft bool res, _, err := a.Search(filters, "", true) // Search for the workspace if err == nil && len(res) > 0 { // If the workspace already exists, return an error return nil, 409, errors.New("a workspace with the same name already exists")