-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement scheduling relative to last task execution (#439)
- Loading branch information
1 parent
44585ed
commit 6ed1280
Showing
26 changed files
with
1,120 additions
and
249 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,42 @@ | ||
package migrations | ||
|
||
import ( | ||
v1 "github.com/garethgeorge/backrest/gen/go/v1" | ||
) | ||
|
||
func convertToRelativeSchedule(sched *v1.Schedule) { | ||
switch s := sched.GetSchedule().(type) { | ||
case *v1.Schedule_MaxFrequencyDays: | ||
sched.Schedule = &v1.Schedule_MinDaysSinceLastRun{ | ||
MinDaysSinceLastRun: s.MaxFrequencyDays, | ||
} | ||
case *v1.Schedule_MaxFrequencyHours: | ||
sched.Schedule = &v1.Schedule_MinHoursSinceLastRun{ | ||
MinHoursSinceLastRun: s.MaxFrequencyHours, | ||
} | ||
case *v1.Schedule_Cron: | ||
sched.Schedule = &v1.Schedule_CronSinceLastRun{ | ||
CronSinceLastRun: s.Cron, | ||
} | ||
default: | ||
// do nothing | ||
} | ||
} | ||
|
||
func migration003RelativeScheduling(config *v1.Config) { | ||
// loop over plans and examine prune policy's | ||
for _, repo := range config.Repos { | ||
prunePolicy := repo.GetPrunePolicy() | ||
if prunePolicy == nil { | ||
continue | ||
} | ||
|
||
if schedule := repo.GetPrunePolicy().GetSchedule(); schedule != nil { | ||
convertToRelativeSchedule(schedule) | ||
} | ||
|
||
if schedule := repo.GetCheckPolicy().GetSchedule(); schedule != nil { | ||
convertToRelativeSchedule(schedule) | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
internal/config/migrations/003relativescheduling_test.go
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,128 @@ | ||
package migrations | ||
|
||
import ( | ||
"testing" | ||
|
||
v1 "github.com/garethgeorge/backrest/gen/go/v1" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func Test003Migration(t *testing.T) { | ||
config := &v1.Config{ | ||
Repos: []*v1.Repo{ | ||
{ | ||
Id: "prune daily", | ||
PrunePolicy: &v1.PrunePolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MaxFrequencyDays{ | ||
MaxFrequencyDays: 1, | ||
}, | ||
}, | ||
}, | ||
CheckPolicy: &v1.CheckPolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MaxFrequencyDays{ | ||
MaxFrequencyDays: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Id: "prune hourly", | ||
PrunePolicy: &v1.PrunePolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MaxFrequencyHours{ | ||
MaxFrequencyHours: 1, | ||
}, | ||
}, | ||
}, | ||
CheckPolicy: &v1.CheckPolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MaxFrequencyHours{ | ||
MaxFrequencyHours: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Id: "prune cron", | ||
PrunePolicy: &v1.PrunePolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_Cron{ | ||
Cron: "0 0 * * *", | ||
}, | ||
}, | ||
}, | ||
CheckPolicy: &v1.CheckPolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_Cron{ | ||
Cron: "0 0 * * *", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
want := &v1.Config{ | ||
Repos: []*v1.Repo{ | ||
{ | ||
Id: "prune daily", | ||
PrunePolicy: &v1.PrunePolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MinDaysSinceLastRun{ | ||
MinDaysSinceLastRun: 1, | ||
}, | ||
}, | ||
}, | ||
CheckPolicy: &v1.CheckPolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MinDaysSinceLastRun{ | ||
MinDaysSinceLastRun: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Id: "prune hourly", | ||
PrunePolicy: &v1.PrunePolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MinHoursSinceLastRun{ | ||
MinHoursSinceLastRun: 1, | ||
}, | ||
}, | ||
}, | ||
CheckPolicy: &v1.CheckPolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_MinHoursSinceLastRun{ | ||
MinHoursSinceLastRun: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Id: "prune cron", | ||
PrunePolicy: &v1.PrunePolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_CronSinceLastRun{ | ||
CronSinceLastRun: "0 0 * * *", | ||
}, | ||
}, | ||
}, | ||
CheckPolicy: &v1.CheckPolicy{ | ||
Schedule: &v1.Schedule{ | ||
Schedule: &v1.Schedule_CronSinceLastRun{ | ||
CronSinceLastRun: "0 0 * * *", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
migration003RelativeScheduling(config) | ||
|
||
if !proto.Equal(config, want) { | ||
t.Errorf("got %v, want %v", config, want) | ||
} | ||
} |
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
Oops, something went wrong.