mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-29 15:49:30 +01:00
Pass peristent store errors up to the router level
This commit is contained in:
parent
eaa8907d17
commit
2845740e97
@ -47,7 +47,7 @@ const apiProtocol = "api"
|
|||||||
|
|
||||||
// New creates a new Gateway object associated with the specified router and
|
// New creates a new Gateway object associated with the specified router and
|
||||||
// following the given configuration.
|
// following the given configuration.
|
||||||
func New(rootLogger *logrus.Logger, cfg *config.Gateway, r *Router) *Gateway {
|
func New(rootLogger *logrus.Logger, cfg *config.Gateway, r *Router) (*Gateway, error) {
|
||||||
logger := rootLogger.WithFields(logrus.Fields{"prefix": "gateway"})
|
logger := rootLogger.WithFields(logrus.Fields{"prefix": "gateway"})
|
||||||
|
|
||||||
cache, _ := lru.New(5000)
|
cache, _ := lru.New(5000)
|
||||||
@ -67,13 +67,25 @@ func New(rootLogger *logrus.Logger, cfg *config.Gateway, r *Router) *Gateway {
|
|||||||
persistentMessageStorePath, usePersistent := gw.Config.GetString("PersistentMessageStorePath")
|
persistentMessageStorePath, usePersistent := gw.Config.GetString("PersistentMessageStorePath")
|
||||||
if usePersistent {
|
if usePersistent {
|
||||||
rootPath := fmt.Sprintf("%s/%s", persistentMessageStorePath, gw.Name)
|
rootPath := fmt.Sprintf("%s/%s", persistentMessageStorePath, gw.Name)
|
||||||
os.MkdirAll(rootPath, os.ModePerm)
|
err := os.MkdirAll(rootPath, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
gw.MessageStore = gw.getMessageMapStore(fmt.Sprintf("%s/Messages", rootPath))
|
return nil, err
|
||||||
gw.CanonicalStore = gw.getMessageMapStore(fmt.Sprintf("%s/Canonical", rootPath))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return gw
|
MessageStore, err := gw.getMessageMapStore(fmt.Sprintf("%s/Messages", rootPath))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
gw.MessageStore = MessageStore
|
||||||
|
|
||||||
|
CanonicalStore, err := gw.getMessageMapStore(fmt.Sprintf("%s/Canonical", rootPath))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
gw.CanonicalStore = CanonicalStore
|
||||||
|
}
|
||||||
|
|
||||||
|
return gw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gw *Gateway) SetMessageMap(canonicalMsgID string, msgIDs []*BrMsgID) {
|
func (gw *Gateway) SetMessageMap(canonicalMsgID string, msgIDs []*BrMsgID) {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/philippgille/gokv/encoding"
|
"github.com/philippgille/gokv/encoding"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gw *Gateway) getMessageMapStore(path string) gokv.Store {
|
func (gw *Gateway) getMessageMapStore(path string) (gokv.Store, error) {
|
||||||
options := badgerdb.Options{
|
options := badgerdb.Options{
|
||||||
Dir: path,
|
Dir: path,
|
||||||
Codec: encoding.Gob,
|
Codec: encoding.Gob,
|
||||||
@ -16,11 +16,12 @@ func (gw *Gateway) getMessageMapStore(path string) gokv.Store {
|
|||||||
|
|
||||||
store, err := badgerdb.NewStore(options)
|
store, err := badgerdb.NewStore(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gw.logger.Error(err)
|
|
||||||
gw.logger.Errorf("Could not connect to db: %s", path)
|
gw.logger.Errorf("Could not connect to db: %s", path)
|
||||||
|
gw.logger.Error(err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return store
|
return store, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gw *Gateway) getCanonicalMessageFromStore(messageID string) string {
|
func (gw *Gateway) getCanonicalMessageFromStore(messageID string) string {
|
||||||
|
@ -50,7 +50,12 @@ func NewRouter(rootLogger *logrus.Logger, cfg config.Config, bridgeMap map[strin
|
|||||||
if _, ok := r.Gateways[entry.Name]; ok {
|
if _, ok := r.Gateways[entry.Name]; ok {
|
||||||
return nil, fmt.Errorf("Gateway with name %s already exists", entry.Name)
|
return nil, fmt.Errorf("Gateway with name %s already exists", entry.Name)
|
||||||
}
|
}
|
||||||
r.Gateways[entry.Name] = New(rootLogger, entry, r)
|
gw, err := New(rootLogger, entry, r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Gateways[entry.Name] = gw
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user