MM-54580: Fix panic in jobs/base_workers.go (#24631)

If GetJob fails, we would return a nil job and then try to log
with that. To prevent this, we keep a reference to the old job
and log with that in the error case.

https://mattermost.atlassian.net/browse/MM-54580

```release-note
Fix a panic where a simple worker would crash if if failed to get a job.
```
Этот коммит содержится в:
Agniva De Sarker
2023-10-03 07:55:38 +05:30
коммит произвёл GitHub
родитель ae1decd1a7
Коммит b9c50641db
3 изменённых файлов: 47 добавлений и 2 удалений

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

@@ -82,13 +82,14 @@ func (worker *SimpleWorker) DoJob(job *model.Job) {
c := request.EmptyContext(worker.logger)
var appErr *model.AppError
// We get the job again because ClaimJob changes the job status.
job, appErr = worker.jobServer.GetJob(c, job.Id)
newJob, appErr := worker.jobServer.GetJob(c, job.Id)
if appErr != nil {
job.Logger.Error("SimpleWorker: job execution error", mlog.Err(appErr))
worker.setJobError(job, appErr)
return
}
job = newJob
err := worker.execute(job)
if err != nil {