fix: fail gracefully when remote XML data cannot be read during sync
This commit is contained in:
@@ -15,8 +15,8 @@ zenstruck_schedule:
|
|||||||
|
|
||||||
- task: app:bpn:xml-sync
|
- task: app:bpn:xml-sync
|
||||||
frequency: '*/15 8-19 * * *'
|
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
|
- task: app:bpn:xml-sync
|
||||||
frequency: '0 20-23,0-7 * * *'
|
frequency: '0 20-23,0-7 * * *'
|
||||||
description: 'Sync BusPro XML data'
|
description: 'Sync BusPro XML data hourly outside peak hours'
|
||||||
|
|||||||
@@ -63,13 +63,12 @@ class BpnXmlSyncCommand extends Command
|
|||||||
$force = $input->getOption('force');
|
$force = $input->getOption('force');
|
||||||
$dryRun = $input->getOption('dry-run');
|
$dryRun = $input->getOption('dry-run');
|
||||||
|
|
||||||
try {
|
$remoteInfo = $this->readRemoteInfo();
|
||||||
$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]);
|
|
||||||
|
|
||||||
return Command::FAILURE;
|
if (null === $remoteInfo) {
|
||||||
|
$io->warning('Remote info unavailable - will retry on next scheduled run');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
$io->text(sprintf(
|
$io->text(sprintf(
|
||||||
@@ -127,11 +126,19 @@ class BpnXmlSyncCommand extends Command
|
|||||||
return Command::SUCCESS;
|
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
|
private function readLocalInfo(): ?XmlExportInfo
|
||||||
|
|||||||
Reference in New Issue
Block a user