MM-31063: Change constants to use CamelCase (#16608)
* MM-31063: Change constants to use CamelCase * store package * change allcaps to camel case (#16615) * New tools.mod Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b6ac5f5d2
Коммит
c1dd23a3c8
@@ -251,7 +251,7 @@ func (th *TestHelper) DeleteAllJobsByTypeAndMigrationKey(jobType string, migrati
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok && key == migrationKey {
|
||||
if key, ok := job.Data[JobDataKeyMigration]; ok && key == migrationKey {
|
||||
if _, err = th.App.Srv().Store.Job().Delete(job.Id); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MIGRATION_STATE_UNSCHEDULED = "unscheduled"
|
||||
MIGRATION_STATE_IN_PROGRESS = "in_progress"
|
||||
MIGRATION_STATE_COMPLETED = "completed"
|
||||
MigrationStateUnscheduled = "unscheduled"
|
||||
MigrationStateInProgress = "in_progress"
|
||||
MigrationStateCompleted = "completed"
|
||||
|
||||
JOB_DATA_KEY_MIGRATION = "migration_key"
|
||||
JOB_DATA_KEY_MIGRATION_LAST_DONE = "last_done"
|
||||
JobDataKeyMigration = "migration_key"
|
||||
JobDataKeyMigration_LAST_DONE = "last_done"
|
||||
)
|
||||
|
||||
type MigrationsJobInterfaceImpl struct {
|
||||
@@ -39,7 +39,7 @@ func MakeMigrationsList() []string {
|
||||
|
||||
func GetMigrationState(migration string, store store.Store) (string, *model.Job, *model.AppError) {
|
||||
if _, err := store.System().GetByName(migration); err == nil {
|
||||
return MIGRATION_STATE_COMPLETED, nil, nil
|
||||
return MigrationStateCompleted, nil, nil
|
||||
}
|
||||
|
||||
jobs, err := store.Job().GetAllByType(model.JOB_TYPE_MIGRATIONS)
|
||||
@@ -48,19 +48,19 @@ func GetMigrationState(migration string, store store.Store) (string, *model.Job,
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
if key, ok := job.Data[JOB_DATA_KEY_MIGRATION]; ok {
|
||||
if key, ok := job.Data[JobDataKeyMigration]; 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
|
||||
return MigrationStateInProgress, job, nil
|
||||
default:
|
||||
return MIGRATION_STATE_UNSCHEDULED, job, nil
|
||||
return MigrationStateUnscheduled, job, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MIGRATION_STATE_UNSCHEDULED, nil, nil
|
||||
return MigrationStateUnscheduled, nil, nil
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestGetMigrationState(t *testing.T) {
|
||||
Id: model.NewId(),
|
||||
CreateAt: model.GetMillis(),
|
||||
Data: map[string]string{
|
||||
JOB_DATA_KEY_MIGRATION: migrationKey,
|
||||
JobDataKeyMigration: migrationKey,
|
||||
},
|
||||
Status: model.JOB_STATUS_PENDING,
|
||||
Type: model.JOB_TYPE_MIGRATIONS,
|
||||
@@ -69,7 +69,7 @@ func TestGetMigrationState(t *testing.T) {
|
||||
Id: model.NewId(),
|
||||
CreateAt: j1.CreateAt + 1,
|
||||
Data: map[string]string{
|
||||
JOB_DATA_KEY_MIGRATION: migrationKey,
|
||||
JobDataKeyMigration: migrationKey,
|
||||
},
|
||||
Status: model.JOB_STATUS_IN_PROGRESS,
|
||||
Type: model.JOB_TYPE_MIGRATIONS,
|
||||
@@ -88,7 +88,7 @@ func TestGetMigrationState(t *testing.T) {
|
||||
Id: model.NewId(),
|
||||
CreateAt: j2.CreateAt + 1,
|
||||
Data: map[string]string{
|
||||
JOB_DATA_KEY_MIGRATION: migrationKey,
|
||||
JobDataKeyMigration: migrationKey,
|
||||
},
|
||||
Status: model.JOB_STATUS_ERROR,
|
||||
Type: model.JOB_TYPE_MIGRATIONS,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MIGRATION_JOB_WEDGED_TIMEOUT_MILLISECONDS = 3600000 // 1 hour
|
||||
MigrationJobWedgedTimeoutMilliseconds = 3600000 // 1 hour
|
||||
)
|
||||
|
||||
type Scheduler struct {
|
||||
@@ -57,9 +57,9 @@ func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, las
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if state == MIGRATION_STATE_IN_PROGRESS {
|
||||
if state == MigrationStateInProgress {
|
||||
// Check the migration job isn't wedged.
|
||||
if job != nil && job.LastActivityAt < model.GetMillis()-MIGRATION_JOB_WEDGED_TIMEOUT_MILLISECONDS && job.CreateAt < model.GetMillis()-MIGRATION_JOB_WEDGED_TIMEOUT_MILLISECONDS {
|
||||
if job != nil && job.LastActivityAt < model.GetMillis()-MigrationJobWedgedTimeoutMilliseconds && job.CreateAt < model.GetMillis()-MigrationJobWedgedTimeoutMilliseconds {
|
||||
mlog.Warn("Job appears to be wedged. Rescheduling another instance.", mlog.String("scheduler", scheduler.Name()), mlog.String("wedged_job_id", job.Id), mlog.String("migration_key", key))
|
||||
if err := scheduler.srv.Jobs.SetJobError(job, nil); err != nil {
|
||||
mlog.Error("Worker: Failed to set job error", mlog.String("scheduler", scheduler.Name()), mlog.String("job_id", job.Id), mlog.String("error", err.Error()))
|
||||
@@ -70,12 +70,12 @@ func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, las
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if state == MIGRATION_STATE_COMPLETED {
|
||||
if state == MigrationStateCompleted {
|
||||
// This migration is done. Continue to check the next.
|
||||
continue
|
||||
}
|
||||
|
||||
if state == MIGRATION_STATE_UNSCHEDULED {
|
||||
if state == MigrationStateUnscheduled {
|
||||
mlog.Debug("Scheduling a new job for migration.", mlog.String("scheduler", scheduler.Name()), mlog.String("migration_key", key))
|
||||
return scheduler.createJob(key, job, scheduler.srv.Store)
|
||||
}
|
||||
@@ -94,12 +94,12 @@ func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, las
|
||||
func (scheduler *Scheduler) createJob(migrationKey string, lastJob *model.Job, store store.Store) (*model.Job, *model.AppError) {
|
||||
var lastDone string
|
||||
if lastJob != nil {
|
||||
lastDone = lastJob.Data[JOB_DATA_KEY_MIGRATION_LAST_DONE]
|
||||
lastDone = lastJob.Data[JobDataKeyMigration_LAST_DONE]
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
JOB_DATA_KEY_MIGRATION: migrationKey,
|
||||
JOB_DATA_KEY_MIGRATION_LAST_DONE: lastDone,
|
||||
JobDataKeyMigration: migrationKey,
|
||||
JobDataKeyMigration_LAST_DONE: lastDone,
|
||||
}
|
||||
|
||||
job, err := scheduler.srv.Jobs.CreateJob(model.JOB_TYPE_MIGRATIONS, data)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TIME_BETWEEN_BATCHES = 100
|
||||
TimeBetweenBatches = 100
|
||||
)
|
||||
|
||||
type Worker struct {
|
||||
@@ -99,8 +99,8 @@ func (worker *Worker) DoJob(job *model.Job) {
|
||||
worker.setJobCanceled(job)
|
||||
return
|
||||
|
||||
case <-time.After(TIME_BETWEEN_BATCHES * time.Millisecond):
|
||||
done, progress, err := worker.runMigration(job.Data[JOB_DATA_KEY_MIGRATION], job.Data[JOB_DATA_KEY_MIGRATION_LAST_DONE])
|
||||
case <-time.After(TimeBetweenBatches * time.Millisecond):
|
||||
done, progress, err := worker.runMigration(job.Data[JobDataKeyMigration], job.Data[JobDataKeyMigration_LAST_DONE])
|
||||
if err != nil {
|
||||
mlog.Error("Worker: Failed to run migration", mlog.String("worker", worker.name), mlog.String("job_id", job.Id), mlog.String("error", err.Error()))
|
||||
worker.setJobError(job, err)
|
||||
@@ -110,7 +110,7 @@ func (worker *Worker) DoJob(job *model.Job) {
|
||||
worker.setJobSuccess(job)
|
||||
return
|
||||
} else {
|
||||
job.Data[JOB_DATA_KEY_MIGRATION_LAST_DONE] = progress
|
||||
job.Data[JobDataKeyMigration_LAST_DONE] = progress
|
||||
if err := worker.srv.Jobs.UpdateInProgressJobData(job); err != nil {
|
||||
mlog.Error("Worker: Failed to update migration status data for job", mlog.String("worker", worker.name), mlog.String("job_id", job.Id), mlog.String("error", err.Error()))
|
||||
worker.setJobError(job, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user