[MM-8497] Ability to set Do Not Disturb for a specified period of time (#17680)
* Revert "Revert "[MM-8497] Ability to set Do Not Disturb for a specified period of time (#16067)" (#17657)"
This reverts commit ff383990f8.
* add debug log for recurring function
* add feature flag for dnd timed status
* refactoring changes
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -209,6 +209,9 @@ type Server struct {
|
||||
|
||||
imgDecoder *imaging.Decoder
|
||||
imgEncoder *imaging.Encoder
|
||||
|
||||
dndTaskMut sync.Mutex
|
||||
dndTask *model.ScheduledTask
|
||||
}
|
||||
|
||||
func NewServer(options ...Option) (*Server, error) {
|
||||
@@ -673,6 +676,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
s.runLicenseExpirationCheckJob()
|
||||
runCheckAdminSupportStatusJob(app, c)
|
||||
runCheckWarnMetricStatusJob(app, c)
|
||||
runDNDStatusExpireJob(app)
|
||||
})
|
||||
s.runJobs()
|
||||
}
|
||||
@@ -689,6 +693,14 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
s.ShutDownPlugins()
|
||||
}
|
||||
})
|
||||
s.AddConfigListener(func(oldCfg, newCfg *model.Config) {
|
||||
if !oldCfg.FeatureFlags.TimedDND && newCfg.FeatureFlags.TimedDND {
|
||||
runDNDStatusExpireJob(app)
|
||||
}
|
||||
if oldCfg.FeatureFlags.TimedDND && !newCfg.FeatureFlags.TimedDND {
|
||||
stopDNDStatusExpireJob(app)
|
||||
}
|
||||
})
|
||||
|
||||
return s, nil
|
||||
}
|
||||
@@ -1051,6 +1063,12 @@ func (s *Server) Shutdown() {
|
||||
mlog.Warn("Error flushing logs", mlog.Err(err))
|
||||
}
|
||||
|
||||
s.dndTaskMut.Lock()
|
||||
if s.dndTask != nil {
|
||||
s.dndTask.Cancel()
|
||||
}
|
||||
s.dndTaskMut.Unlock()
|
||||
|
||||
mlog.Info("Server stopped")
|
||||
|
||||
// this should just write the "server stopped" record, the rest are already flushed.
|
||||
@@ -2284,3 +2302,41 @@ func (s *Server) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
// }
|
||||
// return result, nil
|
||||
// }
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
func cancelDNDStatusExpirationRecurringTask(a *App) {
|
||||
a.srv.dndTaskMut.Lock()
|
||||
if a.srv.dndTask != nil {
|
||||
a.srv.dndTask.Cancel()
|
||||
a.srv.dndTask = nil
|
||||
}
|
||||
a.srv.dndTaskMut.Unlock()
|
||||
}
|
||||
|
||||
func runDNDStatusExpireJob(a *App) {
|
||||
if !a.Config().FeatureFlags.TimedDND {
|
||||
return
|
||||
}
|
||||
if a.IsLeader() {
|
||||
createDNDStatusExpirationRecurringTask(a)
|
||||
}
|
||||
a.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)
|
||||
} else {
|
||||
cancelDNDStatusExpirationRecurringTask(a)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func stopDNDStatusExpireJob(a *App) {
|
||||
if a.IsLeader() {
|
||||
cancelDNDStatusExpirationRecurringTask(a)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user