Add option to ignore failing bridge on start. Fixes #455 (#603)

This commit is contained in:
Wim 2018-11-25 10:35:35 +01:00 committed by GitHub
parent c6fd65d1d7
commit f4d4dc91b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -72,6 +72,7 @@ type Protocol struct {
EditSuffix string // mattermost, slack, discord, telegram, gitter EditSuffix string // mattermost, slack, discord, telegram, gitter
EditDisable bool // mattermost, slack, discord, telegram, gitter EditDisable bool // mattermost, slack, discord, telegram, gitter
IconURL string // mattermost, slack IconURL string // mattermost, slack
IgnoreFailureOnStart bool // general
IgnoreNicks string // all protocols IgnoreNicks string // all protocols
IgnoreMessages string // all protocols IgnoreMessages string // all protocols
Jid string // xmpp Jid string // xmpp

View File

@ -54,17 +54,46 @@ func (r *Router) Start() error {
flog.Infof("Starting bridge: %s ", br.Account) flog.Infof("Starting bridge: %s ", br.Account)
err := br.Connect() err := br.Connect()
if err != nil { if err != nil {
return fmt.Errorf("Bridge %s failed to start: %v", br.Account, err) e := fmt.Errorf("Bridge %s failed to start: %v", br.Account, err)
if r.disableBridge(br, e) {
continue
}
return e
} }
err = br.JoinChannels() err = br.JoinChannels()
if err != nil { if err != nil {
return fmt.Errorf("Bridge %s failed to join channel: %v", br.Account, err) e := fmt.Errorf("Bridge %s failed to join channel: %v", br.Account, err)
if r.disableBridge(br, e) {
continue
}
return e
}
}
// remove unused bridges
for _, gw := range r.Gateways {
for i, br := range gw.Bridges {
if br.Bridger == nil {
flog.Errorf("removing failed bridge %s", i)
delete(gw.Bridges, i)
}
} }
} }
go r.handleReceive() go r.handleReceive()
return nil return nil
} }
// disableBridge returns true and empties a bridge if we have IgnoreFailureOnStart configured
// otherwise returns false
func (r *Router) disableBridge(br *bridge.Bridge, err error) bool {
if r.BridgeValues().General.IgnoreFailureOnStart {
flog.Error(err)
// setting this bridge empty
*br = bridge.Bridge{}
return true
}
return false
}
func (r *Router) getBridge(account string) *bridge.Bridge { func (r *Router) getBridge(account string) *bridge.Bridge {
for _, gw := range r.Gateways { for _, gw := range r.Gateways {
if br, ok := gw.Bridges[account]; ok { if br, ok := gw.Bridges[account]; ok {

View File

@ -1303,6 +1303,12 @@ MediaDownloadSize=1000000
#OPTIONAL (default empty) #OPTIONAL (default empty)
MediaDownloadBlacklist=[".html$",".htm$"] MediaDownloadBlacklist=[".html$",".htm$"]
#IgnoreFailureOnStart allows you to ignore failing bridges on startup.
#Matterbridge will disable the failed bridge and continue with the other ones.
#Context: https://github.com/42wim/matterbridge/issues/455
#OPTIONAL (default false)
IgnoreFailureOnStart=false
################################################################### ###################################################################
#Gateway configuration #Gateway configuration
################################################################### ###################################################################