public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData<ProjectMaintenanceWorkItem>(); Log.Info("Received upgrade projects work item. Update Default Bot List: {0} IncrementConfigurationVersion: {1}", workItem.UpdateDefaultBotList, workItem.IncrementConfigurationVersion); var results = await _projectRepository.GetAllAsync(paging: new PagingOptions().WithLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var project in results.Documents) { if (workItem.UpdateDefaultBotList) project.SetDefaultUserAgentBotPatterns(); if (workItem.IncrementConfigurationVersion) project.Configuration.IncrementVersion(); } if (workItem.UpdateDefaultBotList) await _projectRepository.SaveAsync(results.Documents).AnyContext(); // Sleep so we are not hammering the backend. await Task.Delay(TimeSpan.FromSeconds(2.5)).AnyContext(); await results.NextPageAsync().AnyContext(); if (results.Documents.Count > 0) await context.RenewLockAsync().AnyContext(); } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData <ProjectMaintenanceWorkItem>(); Log.LogInformation("Received upgrade projects work item. Update Default Bot List: {UpdateDefaultBotList} IncrementConfigurationVersion: {IncrementConfigurationVersion}", workItem.UpdateDefaultBotList, workItem.IncrementConfigurationVersion); var results = await _projectRepository.GetAllAsync(o => o.PageLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var project in results.Documents) { if (workItem.UpdateDefaultBotList) { project.SetDefaultUserAgentBotPatterns(); } if (workItem.IncrementConfigurationVersion) { project.Configuration.IncrementVersion(); } if (workItem.RemoveOldUsageStats) { foreach (var usage in project.OverageHours.Where(u => u.Date < SystemClock.UtcNow.Subtract(TimeSpan.FromDays(3))).ToList()) { project.OverageHours.Remove(usage); } foreach (var usage in project.Usage.Where(u => u.Date < SystemClock.UtcNow.Subtract(TimeSpan.FromDays(366))).ToList()) { project.Usage.Remove(usage); } } } if (workItem.UpdateDefaultBotList || workItem.IncrementConfigurationVersion || workItem.RemoveOldUsageStats) { await _projectRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5)).AnyContext(); if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync().AnyContext()) { break; } if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var wi = context.GetData <OrganizationMaintenanceWorkItem>(); Log.LogInformation("Received upgrade organizations work item. Upgrade Plans: {UpgradePlans}", wi.UpgradePlans); var results = await _organizationRepository.GetAllAsync(o => o.PageLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var organization in results.Documents) { if (wi.UpgradePlans) { UpgradePlan(organization); } if (wi.RemoveOldUsageStats) { foreach (var usage in organization.OverageHours.Where(u => u.Date < SystemClock.UtcNow.Subtract(TimeSpan.FromDays(3))).ToList()) { organization.OverageHours.Remove(usage); } foreach (var usage in organization.Usage.Where(u => u.Date < SystemClock.UtcNow.Subtract(TimeSpan.FromDays(366))).ToList()) { organization.Usage.Remove(usage); } } } if (wi.UpgradePlans || wi.RemoveOldUsageStats) { await _organizationRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5)).AnyContext(); if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync().AnyContext()) { break; } if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData <ProjectMaintenanceWorkItem>(); Log.Info("Received upgrade projects work item. Update Default Bot List: {0} IncrementConfigurationVersion: {1}", workItem.UpdateDefaultBotList, workItem.IncrementConfigurationVersion); var results = await _projectRepository.GetAllAsync(o => o.PageLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var project in results.Documents) { if (workItem.UpdateDefaultBotList) { project.SetDefaultUserAgentBotPatterns(); } if (workItem.IncrementConfigurationVersion) { project.Configuration.IncrementVersion(); } } if (workItem.UpdateDefaultBotList) { await _projectRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5)).AnyContext(); if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync().AnyContext()) { break; } if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData <UserMaintenanceWorkItem>(); Log.Info("Received user maintenance work item. Normalize: {0}", workItem.Normalize); var results = await _userRepository.GetAllAsync(paging : new PagingOptions().WithLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var user in results.Documents) { if (workItem.Normalize) { NormalizeUser(user); } } if (workItem.Normalize) { await _userRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5)).AnyContext(); if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync().AnyContext()) { break; } if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData <OrganizationMaintenanceWorkItem>(); Log.Info("Received upgrade organizations work item. Upgrade Plans: {0}", workItem.UpgradePlans); var results = await _organizationRepository.GetAllAsync(o => o.PageLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var organization in results.Documents) { if (workItem.UpgradePlans) { UpgradePlan(organization); } } if (workItem.UpgradePlans) { await _organizationRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5)).AnyContext(); if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync().AnyContext()) { break; } if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData <ProjectMaintenanceWorkItem>(); _logger.Info().Message("Received upgrade projects work item. Update Default Bot List: {0}", workItem.UpdateDefaultBotList).Write(); var results = await _projectRepository.GetAllAsync(paging : new PagingOptions().WithLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var project in results.Documents) { if (workItem.UpdateDefaultBotList) { project.SetDefaultUserAgentBotPatterns(); project.Configuration.IncrementVersion(); } } if (workItem.UpdateDefaultBotList) { await _projectRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await Task.Delay(TimeSpan.FromSeconds(2.5)).AnyContext(); await results.NextPageAsync().AnyContext(); if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData <OrganizationMaintenanceWorkItem>(); _logger.Info().Message("Received upgrade organizations work item. Upgrade Plans: {0}", workItem.UpgradePlans).Write(); var results = await _organizationRepository.GetAllAsync(paging : new PagingOptions().WithLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var organization in results.Documents) { if (workItem.UpgradePlans) { UpgradePlan(organization); } } if (workItem.UpgradePlans) { await _organizationRepository.SaveAsync(results.Documents).AnyContext(); } // Sleep so we are not hammering the backend. await Task.Delay(TimeSpan.FromSeconds(2.5)).AnyContext(); await results.NextPageAsync().AnyContext(); if (results.Documents.Count > 0) { await context.RenewLockAsync().AnyContext(); } } }
public override async Task HandleItemAsync(WorkItemContext context) { const int LIMIT = 100; var workItem = context.GetData<OrganizationMaintenanceWorkItem>(); _logger.Info("Received upgrade organizations work item. Upgrade Plans: {0}", workItem.UpgradePlans); var results = await _organizationRepository.GetAllAsync(paging: new PagingOptions().WithLimit(LIMIT)).AnyContext(); while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) { foreach (var organization in results.Documents) { if (workItem.UpgradePlans) UpgradePlan(organization); } if (workItem.UpgradePlans) await _organizationRepository.SaveAsync(results.Documents).AnyContext(); // Sleep so we are not hammering the backend. await Task.Delay(TimeSpan.FromSeconds(2.5)).AnyContext(); await results.NextPageAsync().AnyContext(); if (results.Documents.Count > 0) await context.RenewLockAsync().AnyContext(); } }