mirror of https://github.com/ouqiang/gocron
定时ping,保持数据库连接
parent
cd7e20c481
commit
beefe59858
2
main.go
2
main.go
|
@ -3,7 +3,7 @@ package main
|
|||
/*--------------------------------------------------------
|
||||
定时任务调度
|
||||
兼容Linux crontab时间格式语法,最小粒度可精确到每秒
|
||||
支持通过HTTP、SSH协议任务执行
|
||||
支持通过HTTP、SSH协议执行任务
|
||||
--------------------------------------------------------*/
|
||||
|
||||
import (
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/ouqiang/cron-scheduler/modules/setting"
|
||||
"gopkg.in/macaron.v1"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Status int8
|
||||
|
@ -42,12 +43,14 @@ func CreateDb(configFile string) *xorm.Engine {
|
|||
mapper := core.NewPrefixMapper(core.SnakeMapper{}, config["prefix"])
|
||||
engine.SetTableMapper(mapper)
|
||||
}
|
||||
// 本地环境开始日志
|
||||
// 本地环境开启日志
|
||||
if macaron.Env == macaron.DEV {
|
||||
engine.ShowSQL(true)
|
||||
engine.Logger().SetLevel(core.LOG_DEBUG)
|
||||
}
|
||||
|
||||
go keepDbAlived(engine)
|
||||
|
||||
return engine
|
||||
}
|
||||
|
||||
|
@ -91,3 +94,12 @@ func getDbConfig(configFile string) map[string]string {
|
|||
|
||||
return db
|
||||
}
|
||||
|
||||
// 定时ping, 防止因数据库超时设置被断开
|
||||
func keepDbAlived(engine *xorm.Engine) {
|
||||
t := time.Tick(180 * time.Second)
|
||||
for {
|
||||
<- t
|
||||
engine.Ping()
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import (
|
|||
type InstallForm struct {
|
||||
DbType string `binding:"IN(mysql)"`
|
||||
DbHost string `binding:"Required"`
|
||||
DbPort int `binding:"Required"`
|
||||
DbPort int `binding:"Required"` // todo 限制端口范围1-65535, 为什么规则未生效?
|
||||
DbUsername string `binding:"Required"`
|
||||
DbPassword string `binding:"Required"`
|
||||
DbName string `binding:"Required"`
|
||||
|
|
Loading…
Reference in New Issue