feat: persist travel snapshots and refresh extended availability

This commit is contained in:
Björn Fromme
2026-03-23 17:29:10 +01:00
parent c1ab6d8687
commit bc7fb794bf
31 changed files with 2328 additions and 91 deletions
@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Service\TravelSnapshotService;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'app:bpn:refresh-travel-snapshot',
description: 'Refreshes active travel snapshots using extended availability data.',
)]
/**
* Console entrypoint for refreshing persisted travel snapshots.
*
* Runs extended availability enrichment in batch mode and triggers
* retention cleanup in the same invocation.
*/
class BpnRefreshTravelSnapshotCommand extends Command
{
public function __construct(
private readonly TravelSnapshotService $snapshotService,
private readonly LoggerInterface $logger,
) {
parent::__construct();
}
/**
* Configures refresh-control and cleanup options.
*/
protected function configure(): void
{
$this
->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Maximum number of snapshots to process', '500')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Refresh even if snapshot was refreshed recently')
->addOption('refresh-after', null, InputOption::VALUE_REQUIRED, 'Minimum minutes since last refresh before a snapshot is eligible (ignored with --force)', '360')
;
}
/**
* Executes snapshot refresh and purge flow.
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$limit = (int) $input->getOption('limit');
$force = true === $input->getOption('force');
$refreshAfterMinutes = (int) $input->getOption('refresh-after');
$result = $this->snapshotService->refreshExtendedSnapshots($limit, $force, $refreshAfterMinutes);
$io->success(sprintf(
'Snapshot refresh complete: %d processed, %d updated, %d failed',
$result['processed'],
$result['updated'],
$result['failed']
));
$this->logger->info('Travel snapshot refresh finished', $result);
$deleted = $this->snapshotService->purgeExpiredSnapshots();
$io->note(sprintf('Deleted %d expired snapshots.', $deleted));
return Command::SUCCESS;
}
}