Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Media;
|
|
use App\Services\Media\ImageProcessor;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
|
|
/**
|
|
* Derives an image's versions off the request.
|
|
*
|
|
* Queued because resampling four widths in two formats takes seconds, and the
|
|
* person who pressed "save" should not be waiting for it. Until it runs the
|
|
* image still serves — just without the extras — so a queue that is behind
|
|
* degrades the page rather than breaking it.
|
|
*/
|
|
class ProcessMedia implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 3;
|
|
|
|
/** @var array<int, int> */
|
|
public array $backoff = [10, 60];
|
|
|
|
public function __construct(public Media $media) {}
|
|
|
|
/**
|
|
* @return array<int, object>
|
|
*/
|
|
public function middleware(): array
|
|
{
|
|
// The safety-net command and an upload can easily land on the same
|
|
// file at once, and both would be writing the same derived paths.
|
|
return [(new WithoutOverlapping("media:{$this->media->id}"))->dontRelease()];
|
|
}
|
|
|
|
public function handle(ImageProcessor $processor): void
|
|
{
|
|
$processor->process($this->media);
|
|
}
|
|
}
|