Improve dashboard health and state recovery
This commit is contained in:
@@ -44,6 +44,18 @@ func TestPreviousWithinCatchUpWindow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreviousScheduledUsesJobTimezone(t *testing.T) {
|
||||
now := time.Date(2026, 7, 13, 8, 0, 0, 0, time.UTC)
|
||||
want := time.Date(2026, 7, 13, 0, 0, 0, 0, time.UTC)
|
||||
got, err := PreviousScheduled("0 2 * * *", "Europe/Berlin", now, 24*time.Hour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("previous scheduled = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCronUsesOrForRestrictedMonthDayAndWeekday(t *testing.T) {
|
||||
expr, err := Parse("0 2 1 * 1")
|
||||
if err != nil {
|
||||
|
||||
@@ -14,6 +14,21 @@ type Enqueue func(model.Job) error
|
||||
type EnqueueMaintenance func(string, string) (model.Run, error)
|
||||
type LastRun func(string) time.Time
|
||||
|
||||
func PreviousScheduled(spec, timezone string, now time.Time, window time.Duration) (time.Time, error) {
|
||||
expression, err := Parse(spec)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
loc := time.Local
|
||||
if timezone != "" {
|
||||
loc, err = time.LoadLocation(timezone)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
return previous(expression, now.In(loc), window).UTC(), nil
|
||||
}
|
||||
|
||||
type Scheduler struct {
|
||||
config ConfigProvider
|
||||
enqueue Enqueue
|
||||
|
||||
Reference in New Issue
Block a user