feat: expose default cron implementation (#906)

This commit is contained in:
John Roesler 2025-12-10 13:57:36 -06:00 committed by GitHub
parent f4c6d141a9
commit 7a1855ef7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -348,6 +348,14 @@ func ExampleMonthlyJob() {
)
}
func ExampleNewDefaultCron() {
c := gocron.NewDefaultCron(true)
err := c.IsValid("* * * * * *", time.Local, time.Now())
if err != nil {
panic(err)
}
}
func ExampleNewScheduler() {
s, _ := gocron.NewScheduler()
defer func() { _ = s.Shutdown() }()

9
job.go
View File

@ -140,6 +140,15 @@ func newDefaultCronImplementation(withSeconds bool) Cron {
}
}
// NewDefaultCron returns the default cron implementation for use outside the
// scheduling of a job. For example, validating crontab syntax before passing to the
// NewJob function.
func NewDefaultCron(cronStatementsIncludeSeconds bool) Cron {
return &defaultCron{
withSeconds: cronStatementsIncludeSeconds,
}
}
var _ Cron = (*defaultCron)(nil)
type defaultCron struct {