-
app/Jobs/SyncSourceFeed.php
Open in GitHubuse App\Models\Source; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Carbon; use willvincent\Feeds\Facades\FeedsFacade; class SyncSourceFeed implements ShouldQueue { use Queueable; public function __construct(public Source $source) {} public function handle(): void { $feed = FeedsFacade::make([$this->source->url], 20, true); if (filled($feed->error())) { $feed = FeedsFacade::make([$this->source->url], 20); } $latestMaterial = $this->source->latestMaterial; foreach ($feed->get_items() as $item) { $itemPublishedAt = Carbon::parse($item->get_date())->timezone(config('app.timezone')); if (filled($latestMaterial) && $latestMaterial->published_at->greaterThanOrEqualTo($itemPublishedAt)) { break; } ProcessFeedItem::dispatch($this->source, $item); } $this->source->updateLastCheckedAt(); } }
-
app/Jobs/ProcessFeedItem.php
Open in GitHubuse App\Actions\CreateMaterial; use App\Data\MaterialData; use App\Models\Source; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; use SimplePie\Item; class ProcessFeedItem implements ShouldQueue { use Queueable; public function __construct( public Source $source, public Item $item ) {} public function handle(CreateMaterial $createMaterial): void { $createMaterial->handle( $this->source, MaterialData::create($this->source->type, $this->item), ); } }