diff options
author | Chris <ccbrown112@gmail.com> | 2018-01-11 15:23:41 -0600 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2018-01-11 13:23:41 -0800 |
commit | 1d9efd0e39a9663bb2fbf52b3353fe21ac3b6954 (patch) | |
tree | 5518bf9683e2fcbcb6b4e0acd3643a3146574ec4 /app/config.go | |
parent | 6990d052d5e95295e729aae28a0d30bfdcb98573 (diff) | |
download | chat-1d9efd0e39a9663bb2fbf52b3353fe21ac3b6954.tar.gz chat-1d9efd0e39a9663bb2fbf52b3353fe21ac3b6954.tar.bz2 chat-1d9efd0e39a9663bb2fbf52b3353fe21ac3b6954.zip |
Remove global config watcher (#8080)
* remove global config watcher
* keep config watcher disabled for tests
* compile fix
* fix resource leak
Diffstat (limited to 'app/config.go')
-rw-r--r-- | app/config.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/app/config.go b/app/config.go new file mode 100644 index 000000000..483804c99 --- /dev/null +++ b/app/config.go @@ -0,0 +1,73 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "crypto/md5" + "encoding/json" + "fmt" + "runtime/debug" + + l4g "github.com/alecthomas/log4go" + + "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" +) + +func (a *App) Config() *model.Config { + return utils.Cfg +} + +func (a *App) UpdateConfig(f func(*model.Config)) { + old := utils.Cfg.Clone() + f(utils.Cfg) + utils.InvokeGlobalConfigListeners(old, utils.Cfg) +} + +func (a *App) PersistConfig() { + utils.SaveConfig(a.ConfigFileName(), a.Config()) +} + +func (a *App) ReloadConfig() { + debug.FreeOSMemory() + utils.LoadGlobalConfig(a.ConfigFileName()) + + // start/restart email batching job if necessary + a.InitEmailBatching() +} + +func (a *App) ConfigFileName() string { + return utils.CfgFileName +} + +func (a *App) ClientConfig() map[string]string { + return a.clientConfig +} + +func (a *App) ClientConfigHash() string { + return a.clientConfigHash +} + +func (a *App) EnableConfigWatch() { + if a.configWatcher == nil && !a.disableConfigWatch { + configWatcher, err := utils.NewConfigWatcher(utils.CfgFileName) + if err != nil { + l4g.Error(err) + } + a.configWatcher = configWatcher + } +} + +func (a *App) DisableConfigWatch() { + if a.configWatcher != nil { + a.configWatcher.Close() + a.configWatcher = nil + } +} + +func (a *App) regenerateClientConfig() { + a.clientConfig = utils.GenerateClientConfig(a.Config(), a.DiagnosticId()) + clientConfigJSON, _ := json.Marshal(a.clientConfig) + a.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON)) +} |