From 11c55d422f29308879a5d5f56ed37b2d989ce566 Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 22 Aug 2024 08:45:26 +0200 Subject: [PATCH] Bug on Format date --- models/booking/booking.go | 3 ++- models/workflow/workflow_mongo_accessor.go | 28 ++++++---------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/models/booking/booking.go b/models/booking/booking.go index 48277df..ec3e0dc 100644 --- a/models/booking/booking.go +++ b/models/booking/booking.go @@ -17,7 +17,7 @@ type Booking struct { DatacenterResourceID string `json:"datacenter_resource_id,omitempty" bson:"datacenter_resource_id,omitempty" validate:"required"` } -func (wfa *Booking) CheckBooking(start time.Time, end *time.Time) (bool, error) { +func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bool, error) { // check if if end == nil { // if no end... then Book like a savage @@ -27,6 +27,7 @@ func (wfa *Booking) CheckBooking(start time.Time, end *time.Time) (bool, error) accessor := wfa.GetAccessor(nil) res, code, err := accessor.Search(&dbs.Filters{ And: map[string][]dbs.Filter{ + "datacenter_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}}, "workflowexecution.state": {{Operator: dbs.EQUAL.String(), Value: workflow_execution.SCHEDULED.EnumIndex()}}, "workflowexecution.execution_date": { {Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(e)}, diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index ca08ab6..8043dde 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -138,18 +138,9 @@ 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 = false - return 200, nil - } var err error nats := tools.NewNATSCaller() - res, code, _ := wfa.LoadOne(id) - if code != 200 { - return 404, errors.New("could not load workflow") - } - r := res.(*Workflow) - if r.Schedule != nil && !realData.ScheduleActive { + if realData.Schedule != nil && !realData.ScheduleActive { mongo.MONGOService.DeleteMultiple(map[string]interface{}{ "state": 1, "workflow_id": id, @@ -158,14 +149,6 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) return 200, err } - if r.Schedule != nil { - if r.Schedule.Start != nil && realData.Schedule.Start != nil && (r.Schedule.Start.Equal(*realData.Schedule.Start) || r.Schedule.Start.After(*realData.Schedule.Start)) { - return 200, nil - } - if r.Schedule.Start == realData.Schedule.Start && r.Schedule.End == realData.Schedule.End && r.Schedule.Cron == realData.Schedule.Cron { - return 200, nil - } - } accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil) execs, err := wfa.getExecutions(id, realData) if err != nil { @@ -197,13 +180,16 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet } func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) { - if code, err := wfa.execution(id, set.(*Workflow), true); err != nil { - return nil, code, err - } res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workflow{}) if code != 200 { return nil, code, err } + avoid := set.(*Workflow).Schedule == nil || (res.(*Workflow).Schedule != nil && res.(*Workflow).Schedule.Start == set.(*Workflow).Schedule.Start && res.(*Workflow).Schedule.End == set.(*Workflow).Schedule.End && res.(*Workflow).Schedule.Cron == set.(*Workflow).Schedule.Cron) + if !avoid { + if code, err := wfa.execution(id, res.(*Workflow), true); err != nil { + return nil, code, err + } + } wfa.execute(res.(*Workflow)) return res, code, err }