github.com/yandex/pandora@v0.5.32/core/schedule/instance_step.go (about) 1 package schedule 2 3 import ( 4 "time" 5 6 "github.com/yandex/pandora/core" 7 ) 8 9 func NewInstanceStep(from, to int64, step int64, stepDuration time.Duration) core.Schedule { 10 var nexts []core.Schedule 11 nexts = append(nexts, NewOnce(from)) 12 13 for i := from + step; i <= to; i += step { 14 nexts = append(nexts, NewConst(0, stepDuration)) 15 nexts = append(nexts, NewOnce(step)) 16 } 17 18 return NewCompositeConf(CompositeConf{nexts}) 19 } 20 21 type InstanceStepConfig struct { 22 From int64 `validate:"min=0"` 23 To int64 `validate:"min=0"` 24 Step int64 `validate:"min=1"` 25 StepDuration time.Duration `validate:"min-time=1ms"` 26 } 27 28 func NewInstanceStepConf(conf InstanceStepConfig) core.Schedule { 29 return NewInstanceStep(conf.From, conf.To, conf.Step, conf.StepDuration) 30 }