diff --git a/server/enterprise/message_export/worker.go b/server/enterprise/message_export/worker.go index 95e1f40ffa..851af7e088 100644 --- a/server/enterprise/message_export/worker.go +++ b/server/enterprise/message_export/worker.go @@ -327,6 +327,12 @@ func (w *MessageExportWorker) initJobData(logger mlog.LoggerIFace, job *model.Jo if previousJob.Data == nil { previousJob.Data = make(map[string]string) } + + // Backwards compatibility for <10.5: + if batchStartTimestamp, prevExists := previousJob.Data["batch_start_timestamp"]; prevExists { + previousJob.Data[shared.JobDataBatchStartTime] = batchStartTimestamp + } + if _, prevExists := previousJob.Data[shared.JobDataBatchStartTime]; !prevExists { exportFromTimestamp := strconv.FormatInt(*w.jobServer.Config().MessageExportSettings.ExportFromTimestamp, 10) logger.Info("Worker: Previously successful job lacks job data, falling back to configured MessageExportSettings.ExportFromTimestamp", mlog.String("export_from_timestamp", exportFromTimestamp)) diff --git a/server/enterprise/message_export/worker_test.go b/server/enterprise/message_export/worker_test.go index 08baa5cf59..348c83fe03 100644 --- a/server/enterprise/message_export/worker_test.go +++ b/server/enterprise/message_export/worker_test.go @@ -188,6 +188,66 @@ func TestInitJobDataPreviousJobWithJobData(t *testing.T) { assert.Equal(t, expectedDir, job.Data[shared.JobDataExportDir]) } +func TestInitJobDataPreviousJobWithJobDataPre105(t *testing.T) { + logger := mlog.CreateConsoleTestLogger(t) + mockStore := &storetest.Store{} + defer mockStore.AssertExpectations(t) + + previousJob := &model.Job{ + Id: st.NewTestID(), + CreateAt: model.GetMillis(), + Status: model.JobStatusSuccess, + Type: model.JobTypeMessageExport, + StartAt: model.GetMillis() - 1000, + LastActivityAt: model.GetMillis() - 1000, + Data: map[string]string{"batch_start_timestamp": "123"}, + } + + job := &model.Job{ + Id: st.NewTestID(), + CreateAt: model.GetMillis(), + Status: model.JobStatusPending, + Type: model.JobTypeMessageExport, + Data: map[string]string{shared.JobDataExportDir: "this-is-the-export-dir"}, + } + + // mock job store returns a previously successful job that has the config that we're looking for, so we use it + mockStore.JobStore.On("GetNewestJobByStatusesAndType", []string{model.JobStatusWarning, model.JobStatusSuccess}, model.JobTypeMessageExport).Return(previousJob, nil) + + worker := &MessageExportWorker{ + jobServer: &jobs.JobServer{ + Store: mockStore, + ConfigService: &testutils.StaticConfigService{ + Cfg: &model.Config{ + // mock config + MessageExportSettings: model.MessageExportSettings{ + EnableExport: model.NewPointer(true), + ExportFormat: model.NewPointer(model.ComplianceExportTypeActiance), + DailyRunTime: model.NewPointer("01:00"), + ExportFromTimestamp: model.NewPointer(int64(0)), + BatchSize: model.NewPointer(10000), + ChannelBatchSize: model.NewPointer(100), + ChannelHistoryBatchSize: model.NewPointer(100), + }, + }, + }, + }, + logger: logger, + } + + now := time.Now() + worker.initJobData(logger, job, now) + + assert.Equal(t, model.ComplianceExportTypeActiance, job.Data[shared.JobDataExportType]) + assert.Equal(t, strconv.Itoa(*worker.jobServer.Config().MessageExportSettings.BatchSize), job.Data[shared.JobDataBatchSize]) + + // Assert the new job picks up the <10.5 job start time: + assert.Equal(t, previousJob.Data[shared.JobDataBatchStartTime], job.Data[shared.JobDataBatchStartTime]) + + expectedDir := "this-is-the-export-dir" + assert.Equal(t, expectedDir, job.Data[shared.JobDataExportDir]) +} + func TestDoJobNoPostsToExport(t *testing.T) { logger := mlog.CreateConsoleTestLogger(t)