-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hoist control for exiting script a level up (#348)
* Hoist control for exiting script a level up * Do not accidentally nil out errors * Log when running schedule * Remove duplicate log line * Warn on cron schedule that will never run
- Loading branch information
Showing
6 changed files
with
204 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 - Offen Authors <[email protected]> | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/robfig/cron/v3" | ||
) | ||
|
||
// checkCronSchedule detects whether the given cron expression will actually | ||
// ever be executed or not. | ||
func checkCronSchedule(expression string) (ok bool) { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
ok = false | ||
} | ||
}() | ||
sched, err := cron.ParseStandard(expression) | ||
if err != nil { | ||
ok = false | ||
return | ||
} | ||
now := time.Now() | ||
sched.Next(now) // panics when the cron would never run | ||
ok = true | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.