fedi-feed-router/routes/console.php

62 lines
2 KiB
PHP
Raw Normal View History

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 19:54:43 +02:00
use App\Enums\PlatformEnum;
use App\Jobs\SyncChannelPostsJob;
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');
}
2025-06-30 21:28:15 +02:00
})->everyFiveMinutes()->name('publish-to-lemmy');
2025-06-30 19:54:43 +02:00
Schedule::call(function () {
$communityId = config('lemmy.community_id');
$communityName = config('lemmy.community');
if ($communityId && $communityName) {
SyncChannelPostsJob::dispatch(
PlatformEnum::LEMMY,
$communityId,
$communityName
);
logger()->info('Dispatched channel posts sync job', [
'platform' => 'lemmy',
'community_id' => $communityId,
'community_name' => $communityName
]);
} else {
logger()->warning('Missing Lemmy community configuration for sync job');
}
})->everyTenMinutes()->name('sync-lemmy-channel-posts');