mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-13 03:28:09 -07:00
fix #1622
Allow users to set max MySQL connections and connection lifetime; set a sane default for max connections if it's not present.
This commit is contained in:
@@ -17,6 +17,8 @@ type Config struct {
|
||||
Password string
|
||||
HistoryDatabase string `yaml:"history-database"`
|
||||
Timeout time.Duration
|
||||
MaxConns int `yaml:"max-conns"`
|
||||
ConnMaxLifetime time.Duration `yaml:"conn-max-lifetime"`
|
||||
|
||||
// XXX these are copied from elsewhere in the config:
|
||||
ExpireTime time.Duration
|
||||
|
||||
@@ -100,6 +100,14 @@ func (m *MySQL) Open() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if m.config.MaxConns != 0 {
|
||||
m.db.SetMaxOpenConns(m.config.MaxConns)
|
||||
m.db.SetMaxIdleConns(m.config.MaxConns)
|
||||
}
|
||||
if m.config.ConnMaxLifetime != 0 {
|
||||
m.db.SetConnMaxLifetime(m.config.ConnMaxLifetime)
|
||||
}
|
||||
|
||||
err = m.fixSchemas()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user