Automatic crontab updates on modifying INTAKE_CRON

This commit is contained in:
Tim Van Baak 2025-02-12 10:14:31 -08:00
parent bd5737ad7a
commit 7446f92cc8
2 changed files with 24 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"log"
"strings"
"github.com/Jaculabilis/intake/core"
"github.com/spf13/cobra"
@ -50,4 +51,16 @@ func sourceEnv(source string, env []string) {
if err := core.SetEnvs(db, source, env); err != nil {
log.Fatalf("failed to set envs: %v", err)
}
for _, envval := range env {
if strings.HasPrefix(envval, "INTAKE_CRON=") {
specs, err := core.GetCronSources(db)
if err != nil {
log.Fatalf("failed to get cron specs: %v", err)
}
if err = core.UpdateCrontab(db, specs); err != nil {
log.Fatalf("failed to update crontab: %v", err)
}
}
}
}

View File

@ -128,6 +128,17 @@ func (env *Env) editSource(writer http.ResponseWriter, req *http.Request) {
http.Error(writer, err.Error(), 500)
return
}
if envName == "INTAKE_CRON" {
specs, err := core.GetCronSources(env.db)
if err != nil {
log.Printf("error: failed to get cron specs: %v", err)
} else {
err = core.UpdateCrontab(env.db, specs)
if err != nil {
log.Printf("error: failed to update crontab: %v", err)
}
}
}
}
actionName := req.PostForm.Get("actionName")