2025-06-29 08:50:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
2025-06-29 09:37:49 +02:00
|
|
|
use App\Console\Commands\FetchNewArticlesCommand;
|
2025-06-30 18:18:30 +02:00
|
|
|
use App\Models\Article;
|
|
|
|
|
use App\Modules\Lemmy\Services\LemmyPublisher;
|
|
|
|
|
use App\Services\Article\ArticleFetcher;
|
2025-06-29 09:37:49 +02:00
|
|
|
use Illuminate\Support\Facades\Schedule;
|
2025-06-29 08:50:03 +02:00
|
|
|
|
2025-06-29 18:34:13 +02:00
|
|
|
Schedule::command(FetchNewArticlesCommand::class)->hourly();
|
2025-06-30 18:18:30 +02:00
|
|
|
|
|
|
|
|
Schedule::call(function () {
|
|
|
|
|
$article = Article::whereDoesntHave('articlePublications')
|
|
|
|
|
->where('is_valid', true)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if ($article) {
|
|
|
|
|
try {
|
|
|
|
|
logger()->info('Publishing article to Lemmy via scheduler', [
|
|
|
|
|
'article_id' => $article->id,
|
|
|
|
|
'url' => $article->url
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$extractedData = ArticleFetcher::fetchArticleData($article);
|
|
|
|
|
LemmyPublisher::fromConfig()->publish($article, $extractedData);
|
|
|
|
|
|
|
|
|
|
logger()->info('Successfully published article to Lemmy', [
|
|
|
|
|
'article_id' => $article->id
|
|
|
|
|
]);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
logger()->error('Failed to publish article to Lemmy via scheduler', [
|
|
|
|
|
'article_id' => $article->id,
|
|
|
|
|
'error' => $e->getMessage()
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
logger()->debug('No unpublished valid articles found for Lemmy publishing');
|
|
|
|
|
}
|
|
|
|
|
})->everyFifteenMinutes()->name('publish-to-lemmy');
|