Files
larablog/app/Domain/Ai/Jobs/GenerateArticleCoverJob.php
T
gouki 3cec4c5e18
CI / PHPUnit (PHP 8.3) (push) Failing after 4s
CI / PHPUnit (PHP 8.2) (push) Failing after 1m9s
CI / Deploy (manual gate) (push) Skipped
wip: article AI polish, category SEO fields, cover generator, membership plan seeder
2026-09-07 18:48:37 +00:00

52 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Domain\Ai\Jobs;
use App\Domain\Media\ArticleCoverService;
use App\Models\Article;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
/**
* Auto-pick a cover from article body embeds / attachments.
* `generate` strategy is reserved for future text-to-image.
*/
class GenerateArticleCoverJob implements ShouldQueue
{
use Queueable;
public function __construct(
public int $articleId,
public string $strategy = 'auto', // auto|from_content|attachment|generate
) {
$this->onQueue('ai-content');
}
public function handle(ArticleCoverService $covers): void
{
$article = Article::query()->find($this->articleId);
if ($article === null) {
return;
}
try {
$covers->apply($article, $this->strategy);
} catch (\Throwable $exception) {
Log::warning('GenerateArticleCoverJob failed.', [
'article_id' => $this->articleId,
'strategy' => $this->strategy,
'message' => $exception->getMessage(),
]);
$article->forceFill([
'cover_status' => ArticleCoverService::STATUS_FAILED,
'cover_generated_at' => now(),
])->save();
}
}
}