From e1b7d52ebcf0777b4f710ee2890b09f72996e1af Mon Sep 17 00:00:00 2001 From: John Roesler Date: Tue, 25 Feb 2025 07:47:40 -0600 Subject: [PATCH] ExampleWithCronImplementation --- example_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/example_test.go b/example_test.go index 7b9fc06..ba5d721 100644 --- a/example_test.go +++ b/example_test.go @@ -636,6 +636,35 @@ func ExampleWithContext() { ) } +var _ gocron.Cron = (*customCron)(nil) + +type customCron struct{} + +func (c customCron) IsValid(crontab string, location *time.Location, now time.Time) error { + return nil +} + +func (c customCron) Next(lastRun time.Time) time.Time { + return time.Now().Add(time.Second) +} + +func ExampleWithCronImplementation() { + s, _ := gocron.NewScheduler() + defer func() { _ = s.Shutdown() }() + _, _ = s.NewJob( + gocron.CronJob( + "* * * * *", + false, + ), + gocron.NewTask( + func() {}, + ), + gocron.WithCronImplementation( + &customCron{}, + ), + ) +} + func ExampleWithDisabledDistributedJobLocker() { // var _ gocron.Locker = (*myLocker)(nil) //