Commit 15fbcc7b by 朱继来

temp1

parent 5d1a96f5
...@@ -13,6 +13,7 @@ type Job struct { ...@@ -13,6 +13,7 @@ type Job struct {
Name string `json:"name"` // 任务名 Name string `json:"name"` // 任务名
Command string `json:"command"` // shell命令 Command string `json:"command"` // shell命令
CronExpr string `json:"cronExpr"` // cron表达式 CronExpr string `json:"cronExpr"` // cron表达式
NodeIp string `json:"nodeIp"`
} }
// 任务调度计划 // 任务调度计划
......
package master package master
import ( import (
"net/http" _"encoding/json"
_"fmt"
"go-crontab/common"
"net" "net"
"time" "net/http"
"strconv" "strconv"
"go-crontab/common" "time"
"encoding/json"
) )
// 任务的HTTP接口 // 任务的HTTP接口
...@@ -24,7 +25,7 @@ var ( ...@@ -24,7 +25,7 @@ var (
func handleJobSave(resp http.ResponseWriter, req *http.Request) { func handleJobSave(resp http.ResponseWriter, req *http.Request) {
var ( var (
err error err error
postJob string //postJob string
job common.Job job common.Job
oldJob *common.Job oldJob *common.Job
bytes []byte bytes []byte
...@@ -35,16 +36,25 @@ func handleJobSave(resp http.ResponseWriter, req *http.Request) { ...@@ -35,16 +36,25 @@ func handleJobSave(resp http.ResponseWriter, req *http.Request) {
goto ERR goto ERR
} }
// 2, 取表单中的job字段 //// 2, 取表单中的job字段
postJob = req.PostForm.Get("job") //postJob = req.PostForm.Get("job_name")
// 3, 反序列化job //
if err = json.Unmarshal([]byte(postJob), &job); err != nil { //// 3, 反序列化job
goto ERR //if err = json.Unmarshal([]byte(postJob), &job); err != nil {
} // goto ERR
//}
// 调整2、3步骤,直接赋值给job
job.Name = req.FormValue("job_name");
job.Command = req.FormValue("command");
job.CronExpr = req.FormValue("cron_expr");
job.NodeIp = req.FormValue("node_ip");
// 4, 保存到etcd // 4, 保存到etcd
if oldJob, err = G_jobMgr.SaveJob(&job); err != nil { if oldJob, err = G_jobMgr.SaveJob(&job); err != nil {
goto ERR goto ERR
} }
// 5, 返回正常应答 ({"errno": 0, "msg": "", "data": {....}}) // 5, 返回正常应答 ({"errno": 0, "msg": "", "data": {....}})
if bytes, err = common.BuildResponse(0, "success", oldJob); err == nil { if bytes, err = common.BuildResponse(0, "success", oldJob); err == nil {
resp.Write(bytes) resp.Write(bytes)
...@@ -52,7 +62,7 @@ func handleJobSave(resp http.ResponseWriter, req *http.Request) { ...@@ -52,7 +62,7 @@ func handleJobSave(resp http.ResponseWriter, req *http.Request) {
return return
ERR: ERR:
// 6, 返回异常应答 // 6, 返回异常应答
if bytes, err = common.BuildResponse(-1, req.PostForm.Get("job_name"), nil); err == nil { if bytes, err = common.BuildResponse(-1, err.Error(), nil); err == nil {
resp.Write(bytes) resp.Write(bytes)
} }
} }
......
...@@ -65,7 +65,7 @@ func (jobMgr *JobMgr) SaveJob(job *common.Job) (oldJob *common.Job, err error) { ...@@ -65,7 +65,7 @@ func (jobMgr *JobMgr) SaveJob(job *common.Job) (oldJob *common.Job, err error) {
) )
// etcd的保存key // etcd的保存key
jobKey = common.JOB_SAVE_DIR + job.Name jobKey = common.JOB_SAVE_DIR + job.NodeIp + "/" + job.Name
// 任务信息json // 任务信息json
if jobValue, err = json.Marshal(job); err != nil { if jobValue, err = json.Marshal(job); err != nil {
return return
......
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