Commit 15fbcc7b by 朱继来

temp1

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