apilogs
This commit is contained in:
40
app/Console/Commands/PollFuelPrices.php
Normal file
40
app/Console/Commands/PollFuelPrices.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\PricesUpdatedEvent;
|
||||
use App\Services\FuelPriceService;
|
||||
use Illuminate\Console\Command;
|
||||
use Throwable;
|
||||
|
||||
class PollFuelPrices extends Command
|
||||
{
|
||||
protected $signature = 'fuel:poll {--full : Also refresh station metadata}';
|
||||
|
||||
protected $description = 'Poll the Fuel Finder API for latest prices';
|
||||
|
||||
public function handle(FuelPriceService $service): int
|
||||
{
|
||||
$fullRefresh = (bool) $this->option('full');
|
||||
|
||||
try {
|
||||
if ($fullRefresh) {
|
||||
$this->info('Refreshing station metadata...');
|
||||
$service->refreshStations();
|
||||
}
|
||||
|
||||
$this->info('Polling fuel prices...');
|
||||
$inserted = $service->pollPrices();
|
||||
|
||||
$this->info("Done. $inserted new price record(s) inserted.");
|
||||
|
||||
PricesUpdatedEvent::dispatch($inserted, $fullRefresh);
|
||||
} catch (Throwable $e) {
|
||||
$this->error("Poll failed: {$e->getMessage()}");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user