feat: add ability to suspend and resume a cron task by ID

This takes advantage of the properties system and allows users to suspend/resume the task at will.
This commit is contained in:
Jose Diaz-Gonzalez
2025-09-21 20:52:57 -04:00
parent 3c7985cd82
commit f99e3a6c9c
6 changed files with 99 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ package cron
import (
"fmt"
"strconv"
"strings"
appjson "github.com/dokku/dokku/plugins/app-json"
@@ -27,6 +28,8 @@ var (
}
)
const MaintenancePropertyPrefix = "maintenance."
// CronTask is a struct that represents a cron task
type CronTask struct {
// ID is a unique identifier for the cron task
@@ -102,6 +105,11 @@ func FetchCronTasks(input FetchCronTasksInput) ([]CronTask, error) {
return tasks, nil
}
properties, err := common.PropertyGetAllByPrefix("cron", appName, MaintenancePropertyPrefix)
if err != nil {
return tasks, fmt.Errorf("Error getting maintenance properties: %w", err)
}
for i, c := range input.AppJSON.Cron {
if c.Command == "" {
if input.WarnToFailure {
@@ -127,7 +135,19 @@ func FetchCronTasks(input FetchCronTasksInput) ([]CronTask, error) {
return tasks, fmt.Errorf("Invalid cron schedule for app %s (schedule %s): %s", appName, c.Schedule, err.Error())
}
maintenance := isAppCronInMaintenance || c.Maintenance
maintenance := c.Maintenance
if value, ok := properties[MaintenancePropertyPrefix+c.Schedule]; ok {
boolValue, err := strconv.ParseBool(value)
if err != nil {
return tasks, fmt.Errorf("Invalid maintenance property for app %s (schedule %s): %s", appName, c.Schedule, err.Error())
}
// only override the maintenance value if the property is set to true
if boolValue {
maintenance = boolValue
}
}
tasks = append(tasks, CronTask{
App: appName,
Command: c.Command,