任务规则添加 id 字段

pull/1/head
Doflatango 8 years ago committed by miraclesu
parent 5a5faeb88b
commit cf70099fd2

@ -5,16 +5,16 @@ import (
"fmt"
"os/exec"
"os/user"
"strconv"
"strings"
"syscall"
"time"
client "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc/mvccpb"
"strconv"
"sunteng/commons/log"
"sunteng/cronsun/conf"
"time"
)
const (
@ -44,6 +44,7 @@ type Job struct {
}
type JobRule struct {
Id string `json:"id"`
Timer string `json:"timer"`
GroupIDs []string `json:"gids"`
NodeIDs []string `json:"nids"`
@ -239,6 +240,13 @@ func (j *Job) Check() error {
j.User = strings.TrimSpace(j.User)
for i := range j.Rules {
id := strings.TrimSpace(j.Rules[i].Id)
if id == "" || strings.HasPrefix(id, "NEW") {
j.Rules[i].Id = NextID()
}
}
// 不修改 Command 的内容,简单判断是否为空
if len(strings.TrimSpace(j.Command)) == 0 {
return ErrEmptyJobCommand

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -80,7 +80,7 @@ export default {
addNewTimer: function(){
if (!this.job.rules) this.job.rules = [];
this.job.rules.push({id: this.randomRuleId()});
this.job.rules.push({id: this.newRandomRuleId()});
},
changeGroup: function(val, text){
@ -106,8 +106,8 @@ export default {
.do();
},
randomRuleId: function(){
return Math.random().toString();
newRandomRuleId: function(){
return 'NEW'+Math.random().toString();
}
},
@ -123,7 +123,9 @@ export default {
vm.job = resp;
if (vm.job.rules) {
for (var i in vm.job.rules) {
vm.job.rules[i].id = vm.randomRuleId();
if (vm.job.rules[i].id.length == 0) {
vm.job.rules[i].id = vm.newRandomRuleId();
}
}
}
}).

Loading…
Cancel
Save