数据库连接设置maxLifeTime
parent
aab450a3bf
commit
09985998ca
|
@ -6,9 +6,9 @@ import (
|
|||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/ouqiang/gocron/internal/modules/app"
|
||||
"github.com/ouqiang/gocron/internal/modules/logger"
|
||||
"github.com/ouqiang/gocron/internal/modules/setting"
|
||||
|
@ -31,13 +31,18 @@ const (
|
|||
)
|
||||
|
||||
const (
|
||||
Page = 1 // 当前页数
|
||||
PageSize = 20 // 每页多少条数据
|
||||
MaxPageSize = 100000 // 每次最多取多少条
|
||||
Page = 1 // 当前页数
|
||||
PageSize = 20 // 每页多少条数据
|
||||
MaxPageSize = 1000 // 每次最多取多少条
|
||||
)
|
||||
|
||||
const DefaultTimeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
const (
|
||||
dbPingInterval = 90 * time.Second
|
||||
dbMaxLiftTime = 2 * time.Hour
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
Page int `xorm:"-"`
|
||||
PageSize int `xorm:"-"`
|
||||
|
@ -73,6 +78,7 @@ func CreateDb() *xorm.Engine {
|
|||
}
|
||||
engine.SetMaxIdleConns(app.Setting.Db.MaxIdleConns)
|
||||
engine.SetMaxOpenConns(app.Setting.Db.MaxOpenConns)
|
||||
engine.DB().SetConnMaxLifetime(dbMaxLiftTime)
|
||||
|
||||
if app.Setting.Db.Prefix != "" {
|
||||
// 设置表前缀
|
||||
|
@ -124,7 +130,7 @@ func getDbEngineDSN(setting *setting.Setting) string {
|
|||
}
|
||||
|
||||
func keepDbAlived(engine *xorm.Engine) {
|
||||
t := time.Tick(180 * time.Second)
|
||||
t := time.Tick(dbPingInterval)
|
||||
for {
|
||||
<-t
|
||||
engine.Ping()
|
||||
|
|
Loading…
Reference in New Issue