Add job and artisan command for generating featured thumbnails

This commit is contained in:
2026-05-06 18:55:08 +02:00
parent bd8a5c14a0
commit 8fa3adf4df
2 changed files with 245 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace App\Jobs;
use App\Models\Artwork;
use App\Services\Images\FeaturedArtworkThumbnailGenerator;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
final class GenerateFeaturedArtworkThumbnailsJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public int $tries = 3;
public int $timeout = 120;
public function __construct(
private readonly int $artworkId,
private readonly bool $force = false,
) {
$queue = (string) config('uploads.featured_thumbnails.queue', 'default');
if ($queue !== '') {
$this->onQueue($queue);
}
}
public function handle(
FeaturedArtworkThumbnailGenerator $generator,
): void {
$artwork = Artwork::withTrashed()->find($this->artworkId);
if (! $artwork instanceof Artwork) {
return;
}
$result = $generator->generate($artwork, $this->force);
if (($result['failed'] ?? []) !== []) {
Log::warning('Featured artwork thumbnail generation had partial failures', [
'artwork_id' => $artwork->id,
'failed_variants' => array_keys((array) $result['failed']),
]);
}
}
}