fix: fail gracefully when remote XML data cannot be read during sync

This commit is contained in:
Björn Fromme
2025-12-22 08:29:57 +01:00
parent c9426eff3b
commit 9291adfdff
2 changed files with 18 additions and 11 deletions
+2 -2
View File
@@ -15,8 +15,8 @@ zenstruck_schedule:
- task: app:bpn:xml-sync
frequency: '*/15 8-19 * * *'
description: 'Sync BusPro XML data'
description: 'Sync BusPro XML data every 15 min. during peak hours'
- task: app:bpn:xml-sync
frequency: '0 20-23,0-7 * * *'
description: 'Sync BusPro XML data'
description: 'Sync BusPro XML data hourly outside peak hours'
+16 -9
View File
@@ -63,13 +63,12 @@ class BpnXmlSyncCommand extends Command
$force = $input->getOption('force');
$dryRun = $input->getOption('dry-run');
try {
$remoteInfo = $this->readRemoteInfo();
} catch (FilesystemException|\InvalidArgumentException $e) {
$io->error(sprintf('Failed to read remote info: %s', $e->getMessage()));
$this->logger->error('XML sync failed: could not read remote info', ['exception' => $e]);
$remoteInfo = $this->readRemoteInfo();
return Command::FAILURE;
if (null === $remoteInfo) {
$io->warning('Remote info unavailable - will retry on next scheduled run');
return Command::SUCCESS;
}
$io->text(sprintf(
@@ -127,11 +126,19 @@ class BpnXmlSyncCommand extends Command
return Command::SUCCESS;
}
private function readRemoteInfo(): XmlExportInfo
private function readRemoteInfo(): ?XmlExportInfo
{
$content = $this->xmlSource->read(XmlExportInfo::getFilename());
try {
$content = $this->xmlSource->read(XmlExportInfo::getFilename());
return XmlExportInfo::fromString($content);
return XmlExportInfo::fromString($content);
} catch (FilesystemException|\InvalidArgumentException $e) {
$this->logger->warning('Could not read remote info file, likely being updated', [
'exception' => $e->getMessage(),
]);
return null;
}
}
private function readLocalInfo(): ?XmlExportInfo