Skip to content

Commit e1b7d52

Browse files
committed
ExampleWithCronImplementation
1 parent 69b4347 commit e1b7d52

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Diff for: example_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,35 @@ func ExampleWithContext() {
636636
)
637637
}
638638

639+
var _ gocron.Cron = (*customCron)(nil)
640+
641+
type customCron struct{}
642+
643+
func (c customCron) IsValid(crontab string, location *time.Location, now time.Time) error {
644+
return nil
645+
}
646+
647+
func (c customCron) Next(lastRun time.Time) time.Time {
648+
return time.Now().Add(time.Second)
649+
}
650+
651+
func ExampleWithCronImplementation() {
652+
s, _ := gocron.NewScheduler()
653+
defer func() { _ = s.Shutdown() }()
654+
_, _ = s.NewJob(
655+
gocron.CronJob(
656+
"* * * * *",
657+
false,
658+
),
659+
gocron.NewTask(
660+
func() {},
661+
),
662+
gocron.WithCronImplementation(
663+
&customCron{},
664+
),
665+
)
666+
}
667+
639668
func ExampleWithDisabledDistributedJobLocker() {
640669
// var _ gocron.Locker = (*myLocker)(nil)
641670
//

0 commit comments

Comments
 (0)