From b4ef1177b2935d4a290ea7c8e9cb3cb859f307f4 Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Wed, 29 Apr 2026 20:21:05 +0100 Subject: [PATCH] refactor: PollFuelPricesJob calls service directly Audit item #11. The job was a one-line Artisan::call wrapper around fuel:poll --full. Routing through Artisan adds output buffering and swallows typed exceptions before they reach the queue's failed-job handler. Now injects FuelPriceService and replicates the --full path (refreshStations + pollPrices + PricesUpdatedEvent) directly. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/Jobs/PollFuelPricesJob.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Jobs/PollFuelPricesJob.php b/app/Jobs/PollFuelPricesJob.php index d9ef216..98d70da 100644 --- a/app/Jobs/PollFuelPricesJob.php +++ b/app/Jobs/PollFuelPricesJob.php @@ -2,16 +2,26 @@ namespace App\Jobs; +use App\Events\PricesUpdatedEvent; +use App\Services\FuelPriceService; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; -use Illuminate\Support\Facades\Artisan; +/** + * Background full station refresh + price poll, dispatched from the admin + * "Trigger Full Poll" button. Mirrors the `fuel:poll --full` command but + * calls the service directly so typed exceptions surface to the queue's + * failed-job handler instead of being swallowed by Artisan output buffering. + */ class PollFuelPricesJob implements ShouldQueue { use Queueable; - public function handle(): void + public function handle(FuelPriceService $service): void { - Artisan::call('fuel:poll', ['--full' => true]); + $service->refreshStations(); + $inserted = $service->pollPrices(); + + PricesUpdatedEvent::dispatch($inserted, true); } }