I've been trying to do some video uploads to s3 via a job, but for an unknown reason, it just gets killed each time i run php artisan queue:work, but the odd thing is that I used the same job to upload a file image instead of a video and for an unknow reasons, it works, it fails only when I try to upload a video.
Here's the job in question:
<?php
namespace App\Jobs;
use File;
use App\Models\Video;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Storage;
class UploadVideo implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $filename;
/**
* Create a new job instance.
*
* @param $filename
* @internal param Video $video
*/
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$file = storage_path() . '/uploads/' . $this->filename;
if (Storage::disk('s3telestream')->put($this->filename, fopen($file, 'r+'))) {
File::delete($file);
}
}
}
Probably the job is timing out, see https://laravel.com/docs/5.4/queues#max-job-attempts-and-timeout
Works like a charm, I was wondering if I can set a timeout relative to the file size being uploaded.
I mean for a 20/30 MB, i can set timeout = 120 but for larger files like 200/500 MB maybe i can bump it up to like timeout = 300.
How should I go about it ?
Maybe you could create multiple queues, e.g. big_upload, medium_upload and small_upload.
dispatch the job on the appropriate queue:
$size = Storage::size($filename);
$job = (new UploadVideo($filename))->onQueue($size > 50 ? 'big_upload' : 'small_upload');
dispatch($job);
then create separate workers for each queue:
php artisan queue:big_upload --timeout=300
php artisan queue:medium_upload --timeout=120
php artisan queue:small_upload --timeout=60
Not really that, problem is that I'm not the one responsible for uploading the videos.
The videos will get uploaded from users so not really sure how it's gonna be.
Never mind, I think i got it.
Most helpful comment
Probably the job is timing out, see https://laravel.com/docs/5.4/queues#max-job-attempts-and-timeout