github.com/yandex/pandora@v0.5.32/core/schedule/step.go (about)

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