Migrate Jobs store to sync by default (#11183)
* Migrate Jobs store to sync by default * Fixing compilation * Fixing compilation * Fixing govet
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bbdd6927de
Коммит
f934502a56
@@ -267,16 +267,15 @@ func (me *TestHelper) ResetRoleMigration() {
|
||||
}
|
||||
|
||||
func (me *TestHelper) DeleteAllJobsByTypeAndMigrationKey(jobType string, migrationKey string) {
|
||||
if res := <-me.App.Srv.Store.Job().GetAllByType(model.JOB_TYPE_MIGRATIONS); res.Err != nil {
|
||||
panic(res.Err)
|
||||
} else {
|
||||
jobs := res.Data.([]*model.Job)
|
||||
jobs, err := me.App.Srv.Store.Job().GetAllByType(model.JOB_TYPE_MIGRATIONS)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok && key == migrationKey {
|
||||
if res := <-me.App.Srv.Store.Job().Delete(job.Id); res.Err != nil {
|
||||
panic(res.Err)
|
||||
}
|
||||
for _, job := range jobs {
|
||||
if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok && key == migrationKey {
|
||||
if _, err = me.App.Srv.Store.Job().Delete(job.Id); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,22 @@ func GetMigrationState(migration string, store store.Store) (string, *model.Job,
|
||||
return MIGRATION_STATE_COMPLETED, nil, nil
|
||||
}
|
||||
|
||||
if result := <-store.Job().GetAllByType(model.JOB_TYPE_MIGRATIONS); result.Err != nil {
|
||||
return "", nil, result.Err
|
||||
} else {
|
||||
for _, job := range result.Data.([]*model.Job) {
|
||||
if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok {
|
||||
if key != migration {
|
||||
continue
|
||||
}
|
||||
jobs, err := store.Job().GetAllByType(model.JOB_TYPE_MIGRATIONS)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
switch job.Status {
|
||||
case model.JOB_STATUS_IN_PROGRESS, model.JOB_STATUS_PENDING:
|
||||
return MIGRATION_STATE_IN_PROGRESS, job, nil
|
||||
default:
|
||||
return MIGRATION_STATE_UNSCHEDULED, job, nil
|
||||
}
|
||||
for _, job := range jobs {
|
||||
if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok {
|
||||
if key != migration {
|
||||
continue
|
||||
}
|
||||
|
||||
switch job.Status {
|
||||
case model.JOB_STATUS_IN_PROGRESS, model.JOB_STATUS_PENDING:
|
||||
return MIGRATION_STATE_IN_PROGRESS, job, nil
|
||||
default:
|
||||
return MIGRATION_STATE_UNSCHEDULED, job, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
@@ -52,7 +53,8 @@ func TestGetMigrationState(t *testing.T) {
|
||||
Type: model.JOB_TYPE_MIGRATIONS,
|
||||
}
|
||||
|
||||
j1 = (<-th.App.Srv.Store.Job().Save(j1)).Data.(*model.Job)
|
||||
j1, err = th.App.Srv.Store.Job().Save(j1)
|
||||
require.Nil(t, err)
|
||||
|
||||
state, job, err = GetMigrationState(migrationKey, th.App.Srv.Store)
|
||||
assert.Nil(t, err)
|
||||
@@ -70,7 +72,8 @@ func TestGetMigrationState(t *testing.T) {
|
||||
Type: model.JOB_TYPE_MIGRATIONS,
|
||||
}
|
||||
|
||||
j2 = (<-th.App.Srv.Store.Job().Save(j2)).Data.(*model.Job)
|
||||
j2, err = th.App.Srv.Store.Job().Save(j2)
|
||||
require.Nil(t, err)
|
||||
|
||||
state, job, err = GetMigrationState(migrationKey, th.App.Srv.Store)
|
||||
assert.Nil(t, err)
|
||||
@@ -88,7 +91,8 @@ func TestGetMigrationState(t *testing.T) {
|
||||
Type: model.JOB_TYPE_MIGRATIONS,
|
||||
}
|
||||
|
||||
j3 = (<-th.App.Srv.Store.Job().Save(j3)).Data.(*model.Job)
|
||||
j3, err = th.App.Srv.Store.Job().Save(j3)
|
||||
require.Nil(t, err)
|
||||
|
||||
state, job, err = GetMigrationState(migrationKey, th.App.Srv.Store)
|
||||
assert.Nil(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user