private async Task <bool> ProcessLeafAsync(CatalogLeafItem leafItem, CancellationToken cancellationToken) { bool success; try { await _throttle.WaitAsync(cancellationToken); if (cancellationToken.IsCancellationRequested) { return(false); } switch (leafItem.Type) { case CatalogLeafType.PackageDelete: var packageDelete = await _client.GetPackageDeleteLeafAsync(leafItem.Url); success = await _leafProcessor.ProcessPackageDeleteAsync(packageDelete); break; case CatalogLeafType.PackageDetails: var packageDetails = await _client.GetPackageDetailsLeafAsync(leafItem.Url); success = await _leafProcessor.ProcessPackageDetailsAsync(packageDetails); break; default: throw new NotSupportedException($"The catalog leaf type '{leafItem.Type}' is not supported."); } } catch (Exception exception) { _logger.LogError( 0, exception, "An exception was thrown while processing leaf {leafUrl}.", leafItem.Url); success = false; } finally { _throttle.Release(); } if (!success) { _logger.LogWarning( "Failed to process leaf {leafUrl} ({packageId} {packageVersion}, {leafType}).", leafItem.Url, leafItem.PackageId, leafItem.PackageVersion, leafItem.Type); } return(success); }
private Task <CatalogLeaf> ProcessLeafAsync(CatalogLeafItem leafItem, CancellationToken token) { switch (leafItem.Type) { case CatalogLeafType.PackageDelete: return(_client.GetPackageDeleteLeafAsync(leafItem.Url, token)); case CatalogLeafType.PackageDetails: return(_client.GetPackageDetailsLeafAsync(leafItem.Url, token)); default: throw new NotSupportedException($"The catalog leaf type '{leafItem.Type}' is not supported."); } }
private async Task <bool> ProcessLeafAsync(CatalogLeafItem leafItem, CancellationToken cancellationToken) { bool success; try { if (leafItem.IsPackageDelete()) { var packageDelete = await _client.GetPackageDeleteLeafAsync(leafItem.CatalogLeafUrl); success = await _leafProcessor.ProcessPackageDeleteAsync(packageDelete, cancellationToken); } else if (leafItem.IsPackageDetails()) { var packageDetails = await _client.GetPackageDetailsLeafAsync(leafItem.CatalogLeafUrl); success = await _leafProcessor.ProcessPackageDetailsAsync(packageDetails, cancellationToken); } else { throw new NotSupportedException($"The catalog leaf type '{leafItem.Type}' is not supported."); } } catch (Exception exception) { _logger.LogError( 0, exception, "An exception was thrown while processing leaf {leafUrl}.", leafItem.CatalogLeafUrl); success = false; } if (!success) { _logger.LogWarning( "Failed to process leaf {leafUrl} ({packageId} {packageVersion}, {leafType}).", leafItem.CatalogLeafUrl, leafItem.PackageId, leafItem.PackageVersion, leafItem.Type); } return(success); }