Laravel job overwriting other jobs?

对着背影说爱祢 提交于 2020-01-06 07:28:10

问题


I'm not too sure how to word this one, but I've got a job called uploadFile, which uses CloudConvert to convert an uploaded file (e.g PDF) to a JPG.

Used in isolation, it all works great. I can upload a file, it'll be saved to S3, then CloudConvert gets the S3 file, converts it and uploads that too. Perfect.

When it's being used by more than one person at a time, the files get mixed up. The filenames are correct (so the variables themselves must be correct), but the actual image processed is someone else's somehow.

$originalFileName = str_replace('.'.$this->extension, '', $this->actualFileName);
$tempName = $originalFileName.'_'.time().'.jpg';
$fileName = $originalFileName.'_'.time();

Storage::disk('s3')->put($folder.$fileName, $file, 'public');

$fileUrl = Storage::disk('s3')->url($fileName);

CloudConvert::file($fileUrl)
    ->withOptions([
        'quality' => 80,
        'resize' => '400x400',
    ])->to(CloudConvert::S3($tempName));

In the above, the file in Storage->put() is correct, as is $tempName and $fileName. Somehow, the file it's converting is wrong, so the output Jpeg is from someone else's upload.

Does anyone have any idea of what I can try? I'm not even sure where to begin debugging that.


回答1:


Simple Exchange time()

$mark = microtime().rand(10,100);
$tempName = $originalFileName.'_'.$mark.'.jpg';
$fileName = $originalFileName.'_'.$mark;



回答2:


Eugh, okay I finally worked it out. CloudConvert needed to be reinstantiated. See thread here, if anyone ever encounters this again.



来源:https://stackoverflow.com/questions/54663274/laravel-job-overwriting-other-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!