private async Task PollAndNotify(IStorageBlobContainer container, ContainerScanInfo containerScanInfo, CancellationToken cancellationToken, List <IStorageBlob> failedNotifications) { cancellationToken.ThrowIfCancellationRequested(); DateTime lastScan = containerScanInfo.LastSweepCycleLatestModified; IEnumerable <IStorageBlob> newBlobs = await PollNewBlobsAsync(container, containerScanInfo, cancellationToken); foreach (IStorageBlob newBlob in newBlobs) { cancellationToken.ThrowIfCancellationRequested(); await NotifyRegistrationsAsync(newBlob, failedNotifications, cancellationToken); } // if the 'LatestModified' has changed, update it in the manager if (containerScanInfo.LastSweepCycleLatestModified > lastScan) { DateTime latestScan = containerScanInfo.LastSweepCycleLatestModified; // It's possible that we had some blobs that we failed to move to the queue. We want to make sure // we continue to find these if the host needs to restart. if (failedNotifications.Any()) { latestScan = failedNotifications.Min(n => n.Properties.LastModified.Value.UtcDateTime); } // Store our timestamp slightly earlier than the last timestamp. This is a failsafe for any blobs that created // milliseconds after our last scan (blob timestamps round to the second). This way we make sure to pick those // up on a host restart. await _blobScanInfoManager.UpdateLatestScanAsync(container.ServiceClient.Credentials.AccountName, container.Name, latestScan.AddMilliseconds(-1)); } }
private async Task PollAndNotify(BlobContainerClient container, ContainerScanInfo containerScanInfo, List <BlobNotification> failedNotifications, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); DateTime lastScan = containerScanInfo.LastSweepCycleLatestModified; // For tracking string clientRequestId = Guid.NewGuid().ToString(); IEnumerable <BlobBaseClient> newBlobs = await PollNewBlobsAsync(container, containerScanInfo, clientRequestId, cancellationToken).ConfigureAwait(false); foreach (var newBlob in newBlobs) { cancellationToken.ThrowIfCancellationRequested(); await NotifyRegistrationsAsync(new BlobWithContainer <BlobBaseClient>(container, newBlob), failedNotifications, clientRequestId, cancellationToken).ConfigureAwait(false); } // if the 'LatestModified' has changed, update it in the manager if (containerScanInfo.LastSweepCycleLatestModified > lastScan) { DateTime latestScan = containerScanInfo.LastSweepCycleLatestModified; // It's possible that we had some blobs that we failed to move to the queue. We want to make sure // we continue to find these if the host needs to restart. if (failedNotifications.Any()) { // TODO (kasobol-msft) this call to GetProperties is suboptimal figure out how to propagate data from listing here. latestScan = failedNotifications.Select(p => p.Blob).Min(n => n.BlobClient.GetProperties().Value.LastModified.UtcDateTime); } // Store our timestamp slightly earlier than the last timestamp. This is a failsafe for any blobs that created // milliseconds after our last scan (blob timestamps round to the second). This way we make sure to pick those // up on a host restart. await _blobScanInfoManager.UpdateLatestScanAsync(container.AccountName, container.Name, latestScan.AddMilliseconds(-1)).ConfigureAwait(false); } }