Automatic crontab updates on modifying INTAKE_CRON
This commit is contained in:
parent
bd5737ad7a
commit
7446f92cc8
@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Jaculabilis/intake/core"
|
"github.com/Jaculabilis/intake/core"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -50,4 +51,16 @@ func sourceEnv(source string, env []string) {
|
|||||||
if err := core.SetEnvs(db, source, env); err != nil {
|
if err := core.SetEnvs(db, source, env); err != nil {
|
||||||
log.Fatalf("failed to set envs: %v", err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,17 @@ func (env *Env) editSource(writer http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(writer, err.Error(), 500)
|
http.Error(writer, err.Error(), 500)
|
||||||
return
|
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")
|
actionName := req.PostForm.Get("actionName")
|
||||||
|
Loading…
Reference in New Issue
Block a user