MM-9728: Online migration for advanced permissions phase 2 (#8744)
* MM-9728: Online migration for advanced permissions phase 2 * Add unit tests for new store functions. * Move migration specific code to own file. * Add migration state function test. * Style fixes. * Add i18n strings. * Fix mocks. * Add TestMain to migrations package tests. * Fix typo. * Fix review comments. * Fix up the "Check if migration is done" check to actually work.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
91557bbd97
Коммит
51bd710ecd
11
jobs/interfaces/migrations_interface.go
Обычный файл
11
jobs/interfaces/migrations_interface.go
Обычный файл
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package interfaces
|
||||
|
||||
import "github.com/mattermost/mattermost-server/model"
|
||||
|
||||
type MigrationsJobInterface interface {
|
||||
MakeWorker() model.Worker
|
||||
MakeScheduler() model.Scheduler
|
||||
}
|
||||
@@ -106,6 +106,13 @@ func (srv *JobServer) SetJobCanceled(job *model.Job) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func (srv *JobServer) UpdateInProgressJobData(job *model.Job) *model.AppError {
|
||||
job.Status = model.JOB_STATUS_IN_PROGRESS
|
||||
job.LastActivityAt = model.GetMillis()
|
||||
result := <-srv.Store.Job().UpdateOptimistically(job, model.JOB_STATUS_IN_PROGRESS)
|
||||
return result.Err
|
||||
}
|
||||
|
||||
func (srv *JobServer) RequestCancellation(jobId string) *model.AppError {
|
||||
if result := <-srv.Store.Job().UpdateStatusOptimistically(jobId, model.JOB_STATUS_PENDING, model.JOB_STATUS_CANCELED); result.Err != nil {
|
||||
return result.Err
|
||||
|
||||
@@ -107,6 +107,13 @@ func (watcher *Watcher) PollAndNotify() {
|
||||
default:
|
||||
}
|
||||
}
|
||||
} else if job.Type == model.JOB_TYPE_MIGRATIONS {
|
||||
if watcher.workers.Migrations != nil {
|
||||
select {
|
||||
case watcher.workers.Migrations.JobChannel() <- *job:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ func (srv *JobServer) InitSchedulers() *Schedulers {
|
||||
schedulers.schedulers = append(schedulers.schedulers, ldapSyncInterface.MakeScheduler())
|
||||
}
|
||||
|
||||
if migrationsInterface := srv.Migrations; migrationsInterface != nil {
|
||||
schedulers.schedulers = append(schedulers.schedulers, migrationsInterface.MakeScheduler())
|
||||
}
|
||||
|
||||
schedulers.nextRunTimes = make([]*time.Time, len(schedulers.schedulers))
|
||||
return schedulers
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package jobs
|
||||
|
||||
import (
|
||||
ejobs "github.com/mattermost/mattermost-server/einterfaces/jobs"
|
||||
tjobs "github.com/mattermost/mattermost-server/jobs/interfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
)
|
||||
@@ -34,6 +35,7 @@ type JobServer struct {
|
||||
ElasticsearchAggregator ejobs.ElasticsearchAggregatorInterface
|
||||
ElasticsearchIndexer ejobs.ElasticsearchIndexerInterface
|
||||
LdapSync ejobs.LdapSyncInterface
|
||||
Migrations tjobs.MigrationsJobInterface
|
||||
}
|
||||
|
||||
func NewJobServer(configService ConfigService, store store.Store) *JobServer {
|
||||
|
||||
@@ -20,6 +20,7 @@ type Workers struct {
|
||||
ElasticsearchIndexing model.Worker
|
||||
ElasticsearchAggregation model.Worker
|
||||
LdapSync model.Worker
|
||||
Migrations model.Worker
|
||||
|
||||
listenerId string
|
||||
}
|
||||
@@ -50,6 +51,10 @@ func (srv *JobServer) InitWorkers() *Workers {
|
||||
workers.LdapSync = ldapSyncInterface.MakeWorker()
|
||||
}
|
||||
|
||||
if migrationsInterface := srv.Migrations; migrationsInterface != nil {
|
||||
workers.Migrations = migrationsInterface.MakeWorker()
|
||||
}
|
||||
|
||||
return workers
|
||||
}
|
||||
|
||||
@@ -77,6 +82,10 @@ func (workers *Workers) Start() *Workers {
|
||||
go workers.LdapSync.Run()
|
||||
}
|
||||
|
||||
if workers.Migrations != nil {
|
||||
go workers.Migrations.Run()
|
||||
}
|
||||
|
||||
go workers.Watcher.Start()
|
||||
})
|
||||
|
||||
@@ -152,6 +161,10 @@ func (workers *Workers) Stop() *Workers {
|
||||
workers.LdapSync.Stop()
|
||||
}
|
||||
|
||||
if workers.Migrations != nil {
|
||||
workers.Migrations.Stop()
|
||||
}
|
||||
|
||||
mlog.Info("Stopped workers")
|
||||
|
||||
return workers
|
||||
|
||||
Ссылка в новой задаче
Block a user