Bug on Format date

This commit is contained in:
mr 2024-08-22 08:45:26 +02:00
parent b8b62dc2c8
commit 11c55d422f
2 changed files with 9 additions and 22 deletions

View File

@ -17,7 +17,7 @@ type Booking struct {
DatacenterResourceID string `json:"datacenter_resource_id,omitempty" bson:"datacenter_resource_id,omitempty" validate:"required"` 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 // check if
if end == nil { if end == nil {
// if no end... then Book like a savage // 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) accessor := wfa.GetAccessor(nil)
res, code, err := accessor.Search(&dbs.Filters{ res, code, err := accessor.Search(&dbs.Filters{
And: map[string][]dbs.Filter{ 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.state": {{Operator: dbs.EQUAL.String(), Value: workflow_execution.SCHEDULED.EnumIndex()}},
"workflowexecution.execution_date": { "workflowexecution.execution_date": {
{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(e)}, {Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(e)},

View File

@ -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) { 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 var err error
nats := tools.NewNATSCaller() nats := tools.NewNATSCaller()
res, code, _ := wfa.LoadOne(id) if realData.Schedule != nil && !realData.ScheduleActive {
if code != 200 {
return 404, errors.New("could not load workflow")
}
r := res.(*Workflow)
if r.Schedule != nil && !realData.ScheduleActive {
mongo.MONGOService.DeleteMultiple(map[string]interface{}{ mongo.MONGOService.DeleteMultiple(map[string]interface{}{
"state": 1, "state": 1,
"workflow_id": id, "workflow_id": id,
@ -158,14 +149,6 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData)
return 200, err 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) accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil)
execs, err := wfa.getExecutions(id, realData) execs, err := wfa.getExecutions(id, realData)
if err != nil { 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) { 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{}) res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workflow{})
if code != 200 { if code != 200 {
return nil, code, err 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)) wfa.execute(res.(*Workflow))
return res, code, err return res, code, err
} }