You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cronsun/bin/node/server.go

58 lines
1.0 KiB

// node 服务
// 用于在所需要执行 cron 任务的机器启动服务,替代 cron 执行所需的任务
package main
import (
"flag"
"runtime"
"sunteng/commons/event"
"sunteng/commons/log"
"sunteng/cronsun/conf"
"sunteng/cronsun/models"
"sunteng/cronsun/node"
)
var (
gomax = flag.Int("gomax",
4, "GOMAXPROCS: the max number of operating system threads that can execute")
)
func main() {
flag.Parse()
//set cpu usage
runtime.GOMAXPROCS(*gomax)
models.InitPwd()
if err := models.Init(); err != nil {
log.Error(err.Error())
return
}
n, err := node.NewNode(conf.Config)
if err != nil {
log.Error(err.Error())
return
}
if err = n.Register(); err != nil {
log.Error(err.Error())
return
}
if err = n.Run(); err != nil {
log.Error(err.Error())
return
}
log.Noticef("cronsun %s service started, Ctrl+C or send kill sign to exit", n.String())
// 注册退出事件
event.On(event.EXIT, n.Stop)
// 监听退出信号
event.Wait()
// 处理退出事件
event.Emit(event.EXIT, nil)
log.Notice("exit success")
}