Move Channels into App (#18623)
* Move Channels into App In this PR, we make Channels as part of App instead of Server. This is part of the transition period of moving fields from Server to Channels. For now, Channels contains Server. So the hierarchy is App -> Channels -> Server. And as a first step, we also move httpService to Channels. ```release-note NONE ``` * Fixing another test ```release-note NONE ``` * new method ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
561bc968c8
Коммит
f0ecdcc5f5
@@ -162,8 +162,6 @@ type Server struct {
|
||||
|
||||
phase2PermissionsMigrationComplete bool
|
||||
|
||||
httpService httpservice.HTTPService
|
||||
|
||||
ImageProxy *imageproxy.ImageProxy
|
||||
|
||||
Audit *audit.Audit
|
||||
@@ -267,9 +265,19 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
// This is called after initLogging() to avoid a race condition.
|
||||
mlog.Info("Server is initializing...", mlog.String("go_version", runtime.Version()))
|
||||
|
||||
// Initialize products
|
||||
for name, initializer := range products {
|
||||
prod, err := initializer(s)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error initializing product: %s", name)
|
||||
}
|
||||
|
||||
s.products[name] = prod
|
||||
}
|
||||
|
||||
// It is important to initialize the hub only after the global logger is set
|
||||
// to avoid race conditions while logging from inside the hub.
|
||||
app := New(ServerConnector(s))
|
||||
app := New(ServerConnector(s.Channels()))
|
||||
app.HubStart()
|
||||
|
||||
if *s.Config().LogSettings.EnableDiagnostics && *s.Config().LogSettings.EnableSentry {
|
||||
@@ -304,8 +312,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
s.tracer = tracer
|
||||
}
|
||||
|
||||
s.httpService = httpservice.MakeHTTPService(s)
|
||||
s.pushNotificationClient = s.httpService.MakeClient(true)
|
||||
s.pushNotificationClient = s.Channels().HTTPService().MakeClient(true)
|
||||
|
||||
s.ImageProxy = imageproxy.MakeImageProxy(s, s.HTTPService(), s.Log)
|
||||
|
||||
@@ -349,6 +356,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return nil, errors.Wrapf(err2, "unable to load Mattermost translation files")
|
||||
}
|
||||
|
||||
// initEnterprise needs to be called after products initialization.
|
||||
s.initEnterprise()
|
||||
|
||||
if s.newStore == nil {
|
||||
@@ -695,16 +703,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
}
|
||||
})
|
||||
|
||||
// Initialize products
|
||||
for name, initializer := range products {
|
||||
prod, err := initializer(s)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error initializing product: %s", name)
|
||||
}
|
||||
|
||||
s.products[name] = prod
|
||||
}
|
||||
|
||||
s.AddConfigListener(func(oldCfg, newCfg *model.Config) {
|
||||
if !oldCfg.FeatureFlags.TimedDND && newCfg.FeatureFlags.TimedDND {
|
||||
runDNDStatusExpireJob(app)
|
||||
@@ -788,10 +786,15 @@ func (s *Server) runJobs() {
|
||||
// Global app options that should be applied to apps created by this server
|
||||
func (s *Server) AppOptions() []AppOption {
|
||||
return []AppOption{
|
||||
ServerConnector(s),
|
||||
ServerConnector(s.Channels()),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Channels() *Channels {
|
||||
ch, _ := s.products["channels"].(*Channels)
|
||||
return ch
|
||||
}
|
||||
|
||||
// Return Database type (postgres or mysql) and current version of Mattermost
|
||||
func (s *Server) DatabaseTypeAndMattermostVersion() (string, string) {
|
||||
mattermostVersion, _ := s.Store.System().GetByName("Version")
|
||||
@@ -1957,7 +1960,7 @@ func (s *Server) TelemetryId() string {
|
||||
}
|
||||
|
||||
func (s *Server) HTTPService() httpservice.HTTPService {
|
||||
return s.httpService
|
||||
return s.Channels().HTTPService()
|
||||
}
|
||||
|
||||
func (s *Server) SetLog(l *mlog.Logger) {
|
||||
@@ -2258,18 +2261,18 @@ func (s *Server) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
// }
|
||||
|
||||
func createDNDStatusExpirationRecurringTask(a *App) {
|
||||
a.srv.dndTaskMut.Lock()
|
||||
a.srv.dndTask = model.CreateRecurringTaskFromNextIntervalTime("Unset DND Statuses", a.UpdateDNDStatusOfUsers, 5*time.Minute)
|
||||
a.srv.dndTaskMut.Unlock()
|
||||
a.ch.srv.dndTaskMut.Lock()
|
||||
a.ch.srv.dndTask = model.CreateRecurringTaskFromNextIntervalTime("Unset DND Statuses", a.UpdateDNDStatusOfUsers, 5*time.Minute)
|
||||
a.ch.srv.dndTaskMut.Unlock()
|
||||
}
|
||||
|
||||
func cancelDNDStatusExpirationRecurringTask(a *App) {
|
||||
a.srv.dndTaskMut.Lock()
|
||||
if a.srv.dndTask != nil {
|
||||
a.srv.dndTask.Cancel()
|
||||
a.srv.dndTask = nil
|
||||
a.ch.srv.dndTaskMut.Lock()
|
||||
if a.ch.srv.dndTask != nil {
|
||||
a.ch.srv.dndTask.Cancel()
|
||||
a.ch.srv.dndTask = nil
|
||||
}
|
||||
a.srv.dndTaskMut.Unlock()
|
||||
a.ch.srv.dndTaskMut.Unlock()
|
||||
}
|
||||
|
||||
func runDNDStatusExpireJob(a *App) {
|
||||
@@ -2279,7 +2282,7 @@ func runDNDStatusExpireJob(a *App) {
|
||||
if a.IsLeader() {
|
||||
createDNDStatusExpirationRecurringTask(a)
|
||||
}
|
||||
a.srv.AddClusterLeaderChangedListener(func() {
|
||||
a.ch.srv.AddClusterLeaderChangedListener(func() {
|
||||
mlog.Info("Cluster leader changed. Determining if unset DNS status task should be running", mlog.Bool("isLeader", a.IsLeader()))
|
||||
if a.IsLeader() {
|
||||
createDNDStatusExpirationRecurringTask(a)
|
||||
|
||||
Ссылка в новой задаче
Block a user