38 lines
984 B
PHP
38 lines
984 B
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Exceptions\PublishException;
|
|
use App\Models\Article;
|
|
use App\Services\Article\ArticleFetcher;
|
|
use App\Services\Publishing\ArticlePublishingService;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
|
|
class PublishToLemmyJob implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 3;
|
|
public array $backoff = [60, 120, 300];
|
|
|
|
public function __construct(
|
|
private readonly Article $article
|
|
) {
|
|
$this->onQueue('publishing');
|
|
}
|
|
|
|
public function handle(): void
|
|
{
|
|
$extractedData = ArticleFetcher::fetchArticleData($this->article);
|
|
|
|
/** @var ArticlePublishingService $publishingService */
|
|
$publishingService = resolve(ArticlePublishingService::class);
|
|
|
|
try {
|
|
$publishingService->publishToRoutedChannels($this->article, $extractedData);
|
|
} catch (PublishException $e) {
|
|
$this->fail($e);
|
|
}
|
|
}
|
|
}
|