mirror of https://github.com/portainer/portainer
fix(api): fix snapshot schedule loading
parent
8a186b4024
commit
acc5218c16
|
@ -116,9 +116,10 @@ func initJobScheduler() portainer.JobScheduler {
|
||||||
return cron.NewJobScheduler()
|
return cron.NewJobScheduler()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter portainer.Snapshotter, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, flags *portainer.CLIFlags) error {
|
func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter portainer.Snapshotter, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, settingsService portainer.SettingsService) error {
|
||||||
if !*flags.Snapshot {
|
settings, err := settingsService.Settings()
|
||||||
return nil
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
schedules, err := scheduleService.SchedulesByJobType(portainer.SnapshotJobType)
|
schedules, err := scheduleService.SchedulesByJobType(portainer.SnapshotJobType)
|
||||||
|
@ -126,21 +127,21 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(schedules) != 0 {
|
var snapshotSchedule *portainer.Schedule
|
||||||
return nil
|
if len(schedules) == 0 {
|
||||||
}
|
|
||||||
|
|
||||||
snapshotJob := &portainer.SnapshotJob{}
|
snapshotJob := &portainer.SnapshotJob{}
|
||||||
|
snapshotSchedule = &portainer.Schedule{
|
||||||
snapshotSchedule := &portainer.Schedule{
|
|
||||||
ID: portainer.ScheduleID(scheduleService.GetNextIdentifier()),
|
ID: portainer.ScheduleID(scheduleService.GetNextIdentifier()),
|
||||||
Name: "system_snapshot",
|
Name: "system_snapshot",
|
||||||
CronExpression: "@every " + *flags.SnapshotInterval,
|
CronExpression: "@every " + settings.SnapshotInterval,
|
||||||
Recurring: true,
|
Recurring: true,
|
||||||
JobType: portainer.SnapshotJobType,
|
JobType: portainer.SnapshotJobType,
|
||||||
SnapshotJob: snapshotJob,
|
SnapshotJob: snapshotJob,
|
||||||
Created: time.Now().Unix(),
|
Created: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
snapshotSchedule = &schedules[0]
|
||||||
|
}
|
||||||
|
|
||||||
snapshotJobContext := cron.NewSnapshotJobContext(endpointService, snapshotter)
|
snapshotJobContext := cron.NewSnapshotJobContext(endpointService, snapshotter)
|
||||||
snapshotJobRunner := cron.NewSnapshotJobRunner(snapshotSchedule, snapshotJobContext)
|
snapshotJobRunner := cron.NewSnapshotJobRunner(snapshotSchedule, snapshotJobContext)
|
||||||
|
@ -150,8 +151,11 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(schedules) == 0 {
|
||||||
return scheduleService.CreateSchedule(snapshotSchedule)
|
return scheduleService.CreateSchedule(snapshotSchedule)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func loadEndpointSyncSystemSchedule(jobScheduler portainer.JobScheduler, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, flags *portainer.CLIFlags) error {
|
func loadEndpointSyncSystemSchedule(jobScheduler portainer.JobScheduler, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, flags *portainer.CLIFlags) error {
|
||||||
if *flags.ExternalEndpoints == "" {
|
if *flags.ExternalEndpoints == "" {
|
||||||
|
@ -538,25 +542,6 @@ func main() {
|
||||||
|
|
||||||
snapshotter := initSnapshotter(clientFactory)
|
snapshotter := initSnapshotter(clientFactory)
|
||||||
|
|
||||||
jobScheduler := initJobScheduler()
|
|
||||||
|
|
||||||
err = loadSchedulesFromDatabase(jobScheduler, jobService, store.ScheduleService, store.EndpointService, fileService)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = loadEndpointSyncSystemSchedule(jobScheduler, store.ScheduleService, store.EndpointService, flags)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = loadSnapshotSystemSchedule(jobScheduler, snapshotter, store.ScheduleService, store.EndpointService, flags)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
jobScheduler.Start()
|
|
||||||
|
|
||||||
endpointManagement := true
|
endpointManagement := true
|
||||||
if *flags.ExternalEndpoints != "" {
|
if *flags.ExternalEndpoints != "" {
|
||||||
endpointManagement = false
|
endpointManagement = false
|
||||||
|
@ -579,6 +564,27 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jobScheduler := initJobScheduler()
|
||||||
|
|
||||||
|
err = loadSchedulesFromDatabase(jobScheduler, jobService, store.ScheduleService, store.EndpointService, fileService)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = loadEndpointSyncSystemSchedule(jobScheduler, store.ScheduleService, store.EndpointService, flags)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if *flags.Snapshot {
|
||||||
|
err = loadSnapshotSystemSchedule(jobScheduler, snapshotter, store.ScheduleService, store.EndpointService, store.SettingsService)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jobScheduler.Start()
|
||||||
|
|
||||||
err = initDockerHub(store.DockerHubService)
|
err = initDockerHub(store.DockerHubService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue