Handle differently when trying to update geolocation and already in progress

This commit is contained in:
Alejandro Celaya
2024-12-15 12:03:01 +01:00
parent 853c50a819
commit 72a962ec6d
4 changed files with 19 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ use Shlinkio\Shlink\IpGeolocation\Exception\DbUpdateException;
use Shlinkio\Shlink\IpGeolocation\Exception\MissingLicenseException;
use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface;
use Symfony\Component\Lock\LockFactory;
use Throwable;
use function sprintf;
@@ -65,7 +66,7 @@ readonly class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
// If most recent attempt is in progress, skip check.
// This is a safety check in case the lock is released before the previous download has finished.
if ($mostRecentDownload?->isInProgress()) {
return GeolocationResult::CHECK_SKIPPED;
return GeolocationResult::UPDATE_IN_PROGRESS;
}
$amountOfErrorsSinceLastSuccess = 0;
@@ -122,6 +123,9 @@ readonly class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
sprintf('%s Prev: %s', $e->getMessage(), $e->getPrevious()?->getMessage() ?? '-'),
);
throw $e;
} catch (Throwable $e) {
$dbUpdate->finishWithError(sprintf('Unknown error: %s', $e->getMessage()));
throw $e;
} finally {
$this->em->flush();
}