mirror of https://github.com/shunfei/cronsun
parent
e608185a96
commit
93832d66a8
|
@ -36,7 +36,7 @@ The goal of this project is to make it much easier to manage jobs on lots of mac
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
`cronsun` support security with `security.json` config. When `opne=true`, job command is only allow local files with special extension on the node.
|
`cronsun` support security with `security.json` config. When `open=true`, job command is only allow local files with special extension on the node.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
36
node/node.go
36
node/node.go
|
@ -193,7 +193,7 @@ func (n *Node) modJob(job *cronsun.Job) {
|
||||||
cmds := oJob.Cmds(n.ID, n.groups)
|
cmds := oJob.Cmds(n.ID, n.groups)
|
||||||
|
|
||||||
for id, cmd := range cmds {
|
for id, cmd := range cmds {
|
||||||
n.addCmd(cmd, true)
|
n.modCmd(cmd, true)
|
||||||
delete(prevCmds, id)
|
delete(prevCmds, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,34 +205,40 @@ func (n *Node) modJob(job *cronsun.Job) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) addCmd(cmd *cronsun.Cmd, notice bool) {
|
func (n *Node) addCmd(cmd *cronsun.Cmd, notice bool) {
|
||||||
|
n.Cron.Schedule(cmd.JobRule.Schedule, cmd)
|
||||||
|
n.cmds[cmd.GetID()] = cmd
|
||||||
|
|
||||||
|
if notice {
|
||||||
|
log.Infof("job[%s] group[%s] rule[%s] timer[%s] has added", cmd.Job.ID, cmd.Job.Group, cmd.JobRule.ID, cmd.JobRule.Timer)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) modCmd(cmd *cronsun.Cmd, notice bool) {
|
||||||
c, ok := n.cmds[cmd.GetID()]
|
c, ok := n.cmds[cmd.GetID()]
|
||||||
if ok {
|
if !ok {
|
||||||
|
n.addCmd(cmd, notice)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sch := c.JobRule.Timer
|
sch := c.JobRule.Timer
|
||||||
*c = *cmd
|
*c = *cmd
|
||||||
|
|
||||||
// 节点执行时间不变,不用更新 cron
|
// 节点执行时间改变,更新 cron
|
||||||
if c.JobRule.Timer == sch {
|
// 否则不用更新 cron
|
||||||
return
|
if c.JobRule.Timer != sch {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
c = cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
n.Cron.Schedule(c.JobRule.Schedule, c)
|
n.Cron.Schedule(c.JobRule.Schedule, c)
|
||||||
if !ok {
|
|
||||||
n.cmds[c.GetID()] = c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if notice {
|
if notice {
|
||||||
log.Infof("job[%s] rule[%s] timer[%s] has added", c.Job.ID, c.JobRule.ID, c.JobRule.Timer)
|
log.Infof("job[%s] group[%s] rule[%s] timer[%s] has updated", c.Job.ID, c.Job.Group, c.JobRule.ID, c.JobRule.Timer)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) delCmd(cmd *cronsun.Cmd) {
|
func (n *Node) delCmd(cmd *cronsun.Cmd) {
|
||||||
delete(n.cmds, cmd.GetID())
|
delete(n.cmds, cmd.GetID())
|
||||||
n.Cron.DelJob(cmd)
|
n.Cron.DelJob(cmd)
|
||||||
log.Infof("job[%s] rule[%s] timer[%s] has deleted", cmd.Job.ID, cmd.JobRule.ID, cmd.JobRule.Timer)
|
log.Infof("job[%s] group[%s] rule[%s] timer[%s] has deleted", cmd.Job.ID, cmd.Job.Group, cmd.JobRule.ID, cmd.JobRule.Timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) addGroup(g *cronsun.Group) {
|
func (n *Node) addGroup(g *cronsun.Group) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Binary = "v0.1.1"
|
const Binary = "v0.1.2"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = fmt.Sprintf("%s (build %s)", Binary, runtime.Version())
|
Version = fmt.Sprintf("%s (build %s)", Binary, runtime.Version())
|
||||||
|
|
17
web/job.go
17
web/job.go
|
@ -115,19 +115,22 @@ func (j *Job) UpdateJob(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove old key
|
||||||
|
// it should be before the put method
|
||||||
|
if len(deleteOldKey) > 0 {
|
||||||
|
if _, err = cronsun.DefalutClient.Delete(deleteOldKey); err != nil {
|
||||||
|
log.Errorf("failed to remove old job key[%s], err: %s.", deleteOldKey, err.Error())
|
||||||
|
outJSONWithCode(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err = cronsun.DefalutClient.Put(job.Key(), string(b))
|
_, err = cronsun.DefalutClient.Put(job.Key(), string(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
outJSONWithCode(w, http.StatusInternalServerError, err.Error())
|
outJSONWithCode(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove old key
|
|
||||||
if len(deleteOldKey) > 0 {
|
|
||||||
if _, err = cronsun.DefalutClient.Delete(deleteOldKey); err != nil {
|
|
||||||
log.Errorf("failed to remove old job key[%s], err: %s.", deleteOldKey, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
outJSONWithCode(w, successCode, nil)
|
outJSONWithCode(w, successCode, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue