models: job 执行结果写入 db

结构与接口
pull/1/head
miraclesu 8 years ago
parent 952d4ee3d5
commit 3dcde33480

@ -7,6 +7,7 @@ import (
client "github.com/coreos/etcd/clientv3"
"sunteng/commons/confutil"
"sunteng/commons/db/imgo"
"sunteng/commons/log"
"sunteng/commons/util"
)
@ -56,6 +57,7 @@ type Conf struct {
Log log.Config
Etcd client.Config
Mgo *imgo.Config
Web webConfig
}

@ -0,0 +1,6 @@
{
"Mgo": {
"Host": "192.168.11.16:3000",
"Database": "cronsun"
}
}

@ -13,31 +13,8 @@ import (
var (
DefalutClient *Client
initialized bool
)
func Init() (err error) {
if initialized {
return
}
if err = initID(); err != nil {
return
}
if err = conf.Init(); err != nil {
return
}
if DefalutClient, err = NewClient(conf.Config); err != nil {
return
}
initialized = true
return
}
type Client struct {
*client.Client

@ -0,0 +1,38 @@
package models
import (
"sunteng/commons/db/imgo"
"sunteng/cronsun/conf"
)
var (
initialized bool
)
func Init() (err error) {
if initialized {
return
}
// init id creator
if err = initID(); err != nil {
return
}
// init config
if err = conf.Init(); err != nil {
return
}
// init etcd client
if DefalutClient, err = NewClient(conf.Config); err != nil {
return
}
// init mongoDB
mgoDB = imgo.NewMdbWithConf(conf.Config.Mgo)
initialized = true
return
}

@ -160,14 +160,16 @@ func (j *Job) String() string {
return string(data)
}
// Run 执行任务
func (j *Job) Run() {
cmd := strings.Split(j.Command, " ")
out, err := exec.Command(cmd[0], cmd[1:]...).Output()
if err != nil {
j.fail(err)
return
}
fmt.Printf("%s\n", out)
j.success(out)
}
func JobKey(group, id string) string {
@ -205,3 +207,12 @@ func (j *Job) Check() error {
return nil
}
// 执行结果写入 mongoDB
func (j *Job) success(out []byte) {
}
func (j *Job) fail(err error) {
}

@ -0,0 +1,13 @@
package models
import (
"sunteng/commons/db/imgo"
)
var (
mgoDB *imgo.Mdb
)
func GetDb() *imgo.Mdb {
return mgoDB
}
Loading…
Cancel
Save