workin exucution scheduler

This commit is contained in:
mr 2024-07-30 09:20:33 +02:00
parent 4730d5b4d4
commit 6ac855394b
3 changed files with 13 additions and 10 deletions

View File

@ -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,

View File

@ -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) {

View File

@ -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"`
}