1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

feat(schedules): add the ability to update a schedule script (#2438)

This commit is contained in:
Anthony Lapenna 2018-11-07 17:19:10 +13:00 committed by GitHub
parent 695c28d4f8
commit 807c830db0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 124 additions and 56 deletions

View file

@ -2,6 +2,7 @@ package schedules
import (
"net/http"
"strconv"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
@ -15,6 +16,7 @@ type scheduleUpdatePayload struct {
Image *string
CronExpression *string
Endpoints []portainer.EndpointID
FileContent *string
}
func (payload *scheduleUpdatePayload) Validate(r *http.Request) error {
@ -41,8 +43,16 @@ func (handler *Handler) scheduleUpdate(w http.ResponseWriter, r *http.Request) *
}
updateJobSchedule := updateSchedule(schedule, &payload)
if updateJobSchedule {
if payload.FileContent != nil {
_, err := handler.FileService.StoreScheduledJobFileFromBytes(strconv.Itoa(scheduleID), []byte(*payload.FileContent))
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist script file changes on the filesystem", err}
}
updateJobSchedule = true
}
if updateJobSchedule {
jobContext := cron.NewScriptExecutionJobContext(handler.JobService, handler.EndpointService, handler.FileService)
jobRunner := cron.NewScriptExecutionJobRunner(schedule.ScriptExecutionJob, jobContext)
err := handler.JobScheduler.UpdateSchedule(schedule, jobRunner)