From 7d32a6619dbf696221ec7828cffb3cb6d2eadedc Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 7 Nov 2018 09:22:30 +1300 Subject: [PATCH] feat(api): add created property for schedules (#2435) --- api/cmd/portainer/main.go | 15 ++++++++++----- api/http/handler/schedules/schedule_create.go | 2 ++ api/portainer.go | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api/cmd/portainer/main.go b/api/cmd/portainer/main.go index b0e7a1a5d..2fffc2a69 100644 --- a/api/cmd/portainer/main.go +++ b/api/cmd/portainer/main.go @@ -3,6 +3,7 @@ package main // import "github.com/portainer/portainer" import ( "encoding/json" "strings" + "time" "github.com/portainer/portainer" "github.com/portainer/portainer/bolt" @@ -136,6 +137,7 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter CronExpression: "@every " + *flags.SnapshotInterval, JobType: portainer.SnapshotJobType, SnapshotJob: snapshotJob, + Created: time.Now().Unix(), } snapshotJobContext := cron.NewSnapshotJobContext(endpointService, snapshotter) @@ -173,6 +175,7 @@ func loadEndpointSyncSystemSchedule(jobScheduler portainer.JobScheduler, schedul CronExpression: "@every " + *flags.SyncInterval, JobType: portainer.EndpointSyncJobType, EndpointSyncJob: endpointSyncJob, + Created: time.Now().Unix(), } endpointSyncJobContext := cron.NewEndpointSyncJobContext(endpointService, *flags.ExternalEndpoints) @@ -194,12 +197,14 @@ func loadSchedulesFromDatabase(jobScheduler portainer.JobScheduler, jobService p for _, schedule := range schedules { - jobContext := cron.NewScriptExecutionJobContext(jobService, endpointService, fileService) - jobRunner := cron.NewScriptExecutionJobRunner(schedule.ScriptExecutionJob, jobContext) + if schedule.JobType == portainer.ScriptExecutionJobType { + jobContext := cron.NewScriptExecutionJobContext(jobService, endpointService, fileService) + jobRunner := cron.NewScriptExecutionJobRunner(schedule.ScriptExecutionJob, jobContext) - err = jobScheduler.CreateSchedule(&schedule, jobRunner) - if err != nil { - return err + err = jobScheduler.CreateSchedule(&schedule, jobRunner) + if err != nil { + return err + } } } diff --git a/api/http/handler/schedules/schedule_create.go b/api/http/handler/schedules/schedule_create.go index 56061ff26..6a7b0deb0 100644 --- a/api/http/handler/schedules/schedule_create.go +++ b/api/http/handler/schedules/schedule_create.go @@ -3,6 +3,7 @@ package schedules import ( "errors" "net/http" + "time" "github.com/asaskevich/govalidator" httperror "github.com/portainer/libhttp/error" @@ -155,6 +156,7 @@ func (handler *Handler) createSchedule(name, image, cronExpression string, endpo CronExpression: cronExpression, JobType: portainer.ScriptExecutionJobType, ScriptExecutionJob: job, + Created: time.Now().Unix(), } jobContext := cron.NewScriptExecutionJobContext(handler.JobService, handler.EndpointService, handler.FileService) diff --git a/api/portainer.go b/api/portainer.go index 06a8c1b62..b337c6d4b 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -251,6 +251,7 @@ type ( ID ScheduleID `json:"Id"` Name string CronExpression string + Created int64 JobType JobType ScriptExecutionJob *ScriptExecutionJob SnapshotJob *SnapshotJob