workin exucution scheduler
This commit is contained in:
parent
4730d5b4d4
commit
6ac855394b
@ -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,
|
||||
|
@ -4,8 +4,8 @@ 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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
|
@ -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"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user