protected override async Task RunInternalAsync(CancellationToken cancellationToken) { var currentMessageCount = await _queue.GetMessageCount(cancellationToken); if (currentMessageCount > _maxRequeueQueueSize) { Logger.LogInformation( "Can't requeue any invalid packages because the queue has too many messages ({CurrentMessageCount} > {MaxRequeueQueueSize})!", currentMessageCount, _maxRequeueQueueSize); return; } var invalidPackages = await _statusService.GetAsync(PackageState.Invalid, cancellationToken); await Task.WhenAll(invalidPackages.Select(invalidPackage => { try { Logger.LogInformation("Requeuing invalid package {PackageId} {PackageVersion}.", invalidPackage.Package.Id, invalidPackage.Package.Version); return(_queue.AddAsync( new PackageValidatorContext(invalidPackage), cancellationToken)); } catch (Exception e) { Logger.LogError("Failed to requeue invalid package {PackageId} {PackageVersion}: {Exception}", invalidPackage.Package.Id, invalidPackage.Package.Version, e); return(Task.FromResult(0)); } })); }
protected override async Task RunInternalAsync(CancellationToken cancellationToken) { var databaseSource = new DatabasePackageStatusOutdatedCheckSource( _galleryCursor, _galleryDatabaseQueryService); var auditingSource = new AuditingStoragePackageStatusOutdatedCheckSource( _deletedCursor, _auditingStorage, LoggerFactory.CreateLogger <AuditingStoragePackageStatusOutdatedCheckSource>()); var sources = new IPackageStatusOutdatedCheckSource[] { databaseSource, auditingSource }; var hasPackagesToProcess = true; while (hasPackagesToProcess) { var currentMessageCount = await _packageValidatorContextQueue.GetMessageCount(cancellationToken); if (currentMessageCount > _maxRequeueQueueSize) { Logger.LogInformation( "Can't continue processing packages because the queue has too many messages ({CurrentMessageCount} > {MaxRequeueQueueSize})!", currentMessageCount, _maxRequeueQueueSize); return; } hasPackagesToProcess = await CheckPackages( sources, cancellationToken); } Logger.LogInformation("All packages have had their status checked."); await _monitoringCursor.LoadAsync(cancellationToken); var newCursorValue = _monitoringCursor.Value - ReprocessRange - ReprocessRange; Logger.LogInformation("Restarting source cursors to {NewCursorValue}.", newCursorValue); foreach (var source in sources) { await source.MoveBackAsync(newCursorValue, cancellationToken); } }
public Task <int?> GetMessageCount(CancellationToken token) { return(_queue.GetMessageCount(token)); }