Documentation ¶
Overview ¶
Example (Parser) ¶
schedule := "0 7 * * *" p := hardloop.Parser{ParseFn: cron.ParseStandard} s, err := p.Parse2(schedule) if err != nil { log.Fatal(err) } now := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC) fmt.Println("Next 5 times:") tmpNow := now for i := 0; i < 5; i++ { tmpNow = s.Next(tmpNow) fmt.Println(tmpNow) } tmpNow = now fmt.Println("Prev 5 times:") for i := 0; i < 5; i++ { tmpNow = s.Prev(tmpNow) fmt.Println(tmpNow) }
Output: Next 5 times: 2023-01-01 07:00:00 +0000 UTC 2023-01-02 07:00:00 +0000 UTC 2023-01-03 07:00:00 +0000 UTC 2023-01-04 07:00:00 +0000 UTC 2023-01-05 07:00:00 +0000 UTC Prev 5 times: 2022-12-31 07:00:00 +0000 UTC 2022-12-30 07:00:00 +0000 UTC 2022-12-29 07:00:00 +0000 UTC 2022-12-28 07:00:00 +0000 UTC 2022-12-27 07:00:00 +0000 UTC
Index ¶
- Variables
- func FindNext(schedules []Schedule, now time.Time) time.Time
- func FindPrev(schedules []Schedule, now time.Time) time.Time
- type DelaySchedule
- type Logger
- type Loop
- func (l *Loop) ChangeStartSchedules(startSpecs []string) error
- func (l *Loop) ChangeStopSchedules(stopSpecs []string) error
- func (l *Loop) IsFunctionRunning() bool
- func (l *Loop) IsLoopRunning() bool
- func (l *Loop) Run(ctx context.Context, wg *sync.WaitGroup)
- func (l *Loop) RunWait(ctx context.Context)
- func (l *Loop) SetFunction(fn func(ctx context.Context, wg *sync.WaitGroup) error, ...)
- func (l *Loop) SetLogger(log Logger)
- type Parser
- type Schedule
- type SpecSchedule
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // GapDurationStart to start the function should be at least 1 second bigger than gap duration. GapDurationStart time.Duration = 1 * time.Second //nolint:revive // more readable // GapDurationStop to stop the function. GapDurationStop time.Duration = 0 //nolint:revive // more readable // ErrCloseLoop is returned when the loop should be closed. ErrCloseLoop = errors.New("close loop") )
View Source
var YearLimit = 5
YearLimit is the maximum number of years to search for a matching time.
Functions ¶
Types ¶
type DelaySchedule ¶ added in v0.2.2
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
func NewLoop ¶
func NewLoop(startSpec, endSpec []string, fn func(ctx context.Context, wg *sync.WaitGroup) error) (*Loop, error)
NewLoop returns a new Loop with the given start and end cron specs and function.
- Standard crontab specs, e.g. "* * * * ?"
- Descriptors, e.g. "@midnight", "@every 1h30m"
func (*Loop) ChangeStartSchedules ¶
ChangeStartSchedules sets the start cron specs. Not effects immediately!
func (*Loop) ChangeStopSchedules ¶
ChangeStopSchedule sets the end cron specs. Not effects immediately!
func (*Loop) IsFunctionRunning ¶
IsFunctionRunning returns true if the function is running.
func (*Loop) IsLoopRunning ¶
IsLoopRunning returns true if the loop is running.
type Parser ¶ added in v0.2.0
Parser is default parser for cron to replacing the functions.
type SpecSchedule ¶
func ParseStandard ¶
func ParseStandard(spec string) (*SpecSchedule, error)
Parse returns a new cron schedule for the given spec.
It accepts
- Standard crontab specs, e.g. "* * * * ?"
- Descriptors, e.g. "@midnight", "@every 1h30m"
Click to show internal directories.
Click to hide internal directories.