Add automatic connection retries

This commit is contained in:
Tulir Asokan
2019-05-17 23:53:57 +03:00
parent 38540d8efb
commit 23747d4917
4 changed files with 73 additions and 14 deletions

View File

@ -33,7 +33,9 @@ type BridgeConfig struct {
UsernameTemplate string `yaml:"username_template"`
DisplaynameTemplate string `yaml:"displayname_template"`
ConnectionTimeout int `yaml:"connection_timeout"`
ConnectionTimeout int `yaml:"connection_timeout"`
MaxConnectionAttempts int `yaml:"max_connection_attempts"`
ReportConnectionRetry bool `yaml:"report_connection_retry"`
CommandPrefix string `yaml:"command_prefix"`
@ -43,6 +45,12 @@ type BridgeConfig struct {
displaynameTemplate *template.Template `yaml:"-"`
}
func (bc *BridgeConfig) setDefaults() {
bc.ConnectionTimeout = 20
bc.MaxConnectionAttempts = 3
bc.ReportConnectionRetry = true
}
type umBridgeConfig BridgeConfig
func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
@ -61,7 +69,7 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
type UsernameTemplateArgs struct {
UserID string
UserID string
}
func (bc BridgeConfig) FormatDisplayname(contact whatsapp.Contact) (string, int8) {

View File

@ -64,6 +64,7 @@ type Config struct {
func (config *Config) setDefaults() {
config.AppService.Database.MaxOpenConns = 20
config.AppService.Database.MaxIdleConns = 2
config.Bridge.setDefaults()
}
func Load(path string) (*Config, error) {