From 6ac855394bba1a44a666e146ee269e21613e6edb Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 30 Jul 2024 09:20:33 +0200 Subject: [PATCH] workin exucution scheduler --- models/workflow/workflow_mongo_accessor.go | 11 +++++++---- models/workflow/workflow_schedule.go | 8 ++++---- models/workflow_execution/workflow_execution.go | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index 89600d1..0abfc57 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -28,20 +28,23 @@ func (wfa *WorkflowMongoAccessor) execution(realData *Workflow, delete bool) (in } if realData.Schedule != nil { accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor() - if realData.Schedule.Start.IsZero() { + if realData.Schedule.Start == nil || realData.Schedule.Start.IsZero() { return 422, errors.New("should get a start date on the scheduler.") } + if realData.Schedule.End != nil && realData.Schedule.End.IsZero() { + realData.Schedule.End = nil + } if len(realData.Schedule.Cron) > 0 { - if realData.Schedule.End.IsZero() { + if realData.Schedule.End == nil { return 422, errors.New("a cron task should got a end date.") } c, err := cron.Parse(realData.Schedule.Cron) if err != nil { return 422, errors.New("Bad cron message: " + err.Error()) } - 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{ - ExecDate: s, + ExecDate: &s, EndDate: realData.Schedule.End, State: workflow_execution.SCHEDULED, WorkflowID: realData.UUID, diff --git a/models/workflow/workflow_schedule.go b/models/workflow/workflow_schedule.go index 97e126a..32c61fb 100644 --- a/models/workflow/workflow_schedule.go +++ b/models/workflow/workflow_schedule.go @@ -3,10 +3,10 @@ package oclib import "time" type WorkflowSchedule struct { - Id string `json:"id"` - Start time.Time `json:"start" bson:"start" validate:"required"` - End time.Time `json:"end,omitempty" bson:"end,omitempty"` - Cron string `json:"cron,omitempty" bson:"cron,omitempty"` + Id string `json:"id"` + Start *time.Time `json:"start" bson:"start" validate:"required"` + End *time.Time `json:"end,omitempty" bson:"end,omitempty"` + Cron string `json:"cron,omitempty" bson:"cron,omitempty"` } func (ws *WorkflowSchedule) GetAllDates() (timetable []time.Time) { diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index 3598d51..a8f5560 100644 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -39,8 +39,8 @@ func (d ScheduledType) EnumIndex() int { type WorkflowExecution struct { UUID string `json:"id,omitempty" bson:"id,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"` + ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` + EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` State ScheduledType `json:"state,omitempty" bson:"state,omitempty" ` WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` }