Commit 38d5b952 by 朱继来

调整etcd任务名

parent 24b0984e
Showing with 12 additions and 8 deletions
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
// 定时任务 // 定时任务
type Job struct { type Job struct {
Name string `json:"name"` // 任务名 Name string `json:"name"` // 任务名
JobEtcdName string `json:"job_etcd_name"` // 任务名
Command string `json:"command"` // shell命令 Command string `json:"command"` // shell命令
CronExpr string `json:"cronExpr"` // cron表达式 CronExpr string `json:"cronExpr"` // cron表达式
} }
...@@ -85,6 +86,7 @@ type SortLogByStartTime struct { ...@@ -85,6 +86,7 @@ type SortLogByStartTime struct {
type CronJobs struct { type CronJobs struct {
//Id primitive.ObjectID `bson:"_id"` //Id primitive.ObjectID `bson:"_id"`
JobName string `bson:"job_name"` // 任务名字 JobName string `bson:"job_name"` // 任务名字
JobEtcdName string `bson:"job_etcd_name"` // etcd任务名字
EtcdKey string `bson:"etcd_key"` // etcd key EtcdKey string `bson:"etcd_key"` // etcd key
Node string `bson:"node"` // 所属节点 Node string `bson:"node"` // 所属节点
Group int64 `bson:"group"` // 所属分组 Group int64 `bson:"group"` // 所属分组
......
...@@ -90,18 +90,19 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error) ...@@ -90,18 +90,19 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error)
) )
// 赋值给job // 赋值给job
job.Name = req.FormValue("job_name"); job.Name = req.FormValue("job_name")
job.Command = req.FormValue("command"); job.JobEtcdName = req.FormValue("job_etcd_name")
job.CronExpr = req.FormValue("cron_expr"); job.Command = req.FormValue("command")
nodeIp := req.FormValue("node"); job.CronExpr = req.FormValue("cron_expr")
nodeIp := req.FormValue("node")
// 任务类型:1-普通任务,2-一次性任务 // 任务类型:1-普通任务,2-一次性任务
job_type, err := strconv.ParseInt(req.FormValue("job_type"), 10, 64) job_type, err := strconv.ParseInt(req.FormValue("job_type"), 10, 64)
if job_type == 1 { if job_type == 1 {
jobKey = common.JOB_SAVE_DIR + nodeIp + "/" + job.Name // etcd的保存key: 目录 + IP + 任务名称 jobKey = common.JOB_SAVE_DIR + nodeIp + "/" + job.JobEtcdName // etcd的保存key: 目录 + IP + 任务名称
} else { } else {
jobKey = common.JOB_ONCE_SAVE_DIR + nodeIp + "/" + job.Name // etcd的保存key: 目录 + IP + 任务名称 jobKey = common.JOB_ONCE_SAVE_DIR + nodeIp + "/" + job.JobEtcdName // etcd的保存key: 目录 + IP + 任务名称
} }
// 任务信息json // 任务信息json
...@@ -125,6 +126,7 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error) ...@@ -125,6 +126,7 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error)
// 同步保存到mongo // 同步保存到mongo
cron_job_id := req.FormValue("id") cron_job_id := req.FormValue("id")
cronJob.JobName = req.FormValue("job_name") cronJob.JobName = req.FormValue("job_name")
cronJob.JobEtcdName = req.FormValue("job_etcd_name")
cronJob.EtcdKey = jobKey cronJob.EtcdKey = jobKey
cronJob.Node = req.FormValue("node") cronJob.Node = req.FormValue("node")
cronJob.Group, err = strconv.ParseInt(req.FormValue("group"), 10, 64) cronJob.Group, err = strconv.ParseInt(req.FormValue("group"), 10, 64)
...@@ -150,8 +152,8 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error) ...@@ -150,8 +152,8 @@ func (jobMgr *JobMgr) SaveJob(req *http.Request) (oldJob *common.Job, err error)
cronJob.UpdateTime = time.Now().Unix() cronJob.UpdateTime = time.Now().Unix()
// 修改部分值 // 修改部分值
update := bson.M{"$set": bson.M{"node": cronJob.Node, "group": cronJob.Group, "command": cronJob.Command, update := bson.M{"$set": bson.M{"job_etcd_name": cronJob.JobEtcdName, "etcd_key": cronJob.EtcdKey, "node": cronJob.Node, "group": cronJob.Group, "command": cronJob.Command,
"cron_expr": cronJob.CronExpr, "concurrency_num": cronJob.ConcurrencyNum, "update_time": cronJob.UpdateTime}} "cron_expr": cronJob.CronExpr, "concurrency_num": cronJob.ConcurrencyNum, "modifier": cronJob.Modifier, "update_time": cronJob.UpdateTime}}
objectId, err := primitive.ObjectIDFromHex(cron_job_id) objectId, err := primitive.ObjectIDFromHex(cron_job_id)
_, err = jobMgr.jobCollection.UpdateOne(context.TODO(), bson.M{"_id": objectId}, update) _, err = jobMgr.jobCollection.UpdateOne(context.TODO(), bson.M{"_id": objectId}, update)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment