[MM-63314] Fix ClaimJob in HA environments (#30383)

* ClaimJob now returns newly claimed job

* internal code affected by change

* test changes required

* two branches: for mysql, use transaction; for postgres, use returning

* two branches: for mysql, use transaction; for postgres, use returning

* use same millis value for LastActivityAt and StartAt

* blank commit

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Christopher Poile
2025-03-14 10:24:26 -04:00
коммит произвёл GitHub
родитель c9504925e6
Коммит c049748b88
25 изменённых файлов: 292 добавлений и 183 удалений

Просмотреть файл

@@ -941,27 +941,25 @@ func TestExportFileWarnings(t *testing.T) {
job, appErr := th.App.Srv().Jobs.CreateJob(th.Context, model.JobTypeExportProcess, nil)
require.Nil(t, appErr)
ok, appErr := th.App.Srv().Jobs.ClaimJob(job)
require.Nil(t, appErr)
require.True(t, ok)
job, appErr = th.App.Srv().Jobs.GetJob(th.Context, job.Id)
newJob, appErr := th.App.Srv().Jobs.ClaimJob(job)
require.Nil(t, appErr)
require.NotNil(t, newJob)
opts := model.BulkExportOpts{
IncludeAttachments: true,
CreateArchive: true,
}
appErr = th.App.BulkExport(th.Context, exportFile, dir, job, opts)
appErr = th.App.BulkExport(th.Context, exportFile, dir, newJob, opts)
// should not get an error for the missing file
require.Nil(t, appErr)
// should get a warning instead:
testlib.AssertLog(t, buffer, mlog.LvlWarn.Name, "Unable to export file attachment")
// should get info in the job data:
job, appErr = th.App.Srv().Jobs.GetJob(th.Context, job.Id)
// should get info in the newJob data:
newJob, appErr = th.App.Srv().Jobs.GetJob(th.Context, newJob.Id)
require.Nil(t, appErr)
warnings, ok := job.Data["num_warnings"]
warnings, ok := newJob.Data["num_warnings"]
require.True(t, ok)
require.Equal(t, "1", warnings)