Added license change listener (#24342)

* Added license change listener

* Fixed location of adding license listener

* Made tests unaffected

* Minor refactoring

* Changed order of checks to avoid breaking all tests

* Using CreateJobOnce to handle HA

* Updated context

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Harshil Sharma 2023-11-27 08:49:10 +05:30 committed by GitHub
parent 6561f6f4ff
commit 1a49b7e929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -555,20 +555,27 @@ func (s *Server) doPostPriorityConfigDefaultTrueMigration() {
}
func (s *Server) doElasticsearchFixChannelIndex(c request.CTX) {
s.AddLicenseListener(func(oldLicense, newLicense *model.License) {
s.elasticsearchFixChannelIndex(c, newLicense)
})
s.elasticsearchFixChannelIndex(c, s.License())
}
func (s *Server) elasticsearchFixChannelIndex(c request.CTX, license *model.License) {
if model.BuildEnterpriseReady != "true" || license == nil || !*license.Features.Elasticsearch {
mlog.Debug("Skipping triggering Elasticsearch channel index fix job as build is not Enterprise ready")
return
}
// If the migration is already marked as completed, don't do it again.
if _, err := s.Store().System().GetByName(model.MigrationKeyElasticsearchFixChannelIndex); err == nil {
mlog.Debug("Skipping triggering Elasticsearch channel index fix job as it is already marked completed in database")
return
}
license := s.License()
if model.BuildEnterpriseReady != "true" || license == nil || !*license.Features.Elasticsearch {
mlog.Info("Skipping triggering Elasticsearch channel index fix job as build is not Enterprise ready")
return
}
if _, appErr := s.Jobs.CreateJob(c, model.JobTypeElasticsearchFixChannelIndex, nil); appErr != nil {
if _, appErr := s.Jobs.CreateJobOnce(c, model.JobTypeElasticsearchFixChannelIndex, nil); appErr != nil {
mlog.Fatal("failed to start job for fixing Elasticsearch channels index", mlog.Err(appErr))
return
}
}