public void CleanUpReport(RetentionSettings retentionSettings, IDataReaderService reader, IDataWriterService writer) { _logger.Debug($"Running Clean up job: deleting all runs older than {retentionSettings.Till} and leaving {retentionSettings.Amount} runs only"); var runInfos = reader.GetRunInfos().OrderByDescending(ri => ri.Finish).ToList(); var runInfosToDelete = runInfos.Skip(retentionSettings.Amount).ToList(); runInfosToDelete.AddRange(runInfos.Take(retentionSettings.Amount).Where(ri => ri.Finish < retentionSettings.Till)); foreach (var itemInfoDto in runInfosToDelete) { var run = reader.GetRun(itemInfoDto.Guid); if (run != null) { var tests = reader.GetTestRunsFromRun(run); foreach (var test in tests) { var testOutput = reader.GetTestOutput(test); var screenshots = reader.GetTestScreenshots(test); foreach (var screenshot in screenshots) { _actionHelper.Simple(() => { writer.DeleteTestScreenshot(test, screenshot); }); } _actionHelper.Simple(() => { writer.DeleteTestOutput(test, testOutput); }); _actionHelper.Simple(() => { writer.DeleteTest(test); }); } } _actionHelper.Simple(() => { writer.DeleteRun(itemInfoDto); }); } _logger.Debug("Running Clean up job: done."); }
/// <summary> /// Creates and updates the retention settings in days /// </summary> /// <remarks> /// Creates and updates the retention settings in days /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='retentionInDays'> /// The amount of days to keep the crashes for this application. /// retention_in_days is an enum value, can only be 28 or 90. /// </param> /// <param name='ownerName'> /// The name of the owner /// </param> /// <param name='appName'> /// The name of the application /// </param> public static RetentionSettings UpsertRetentionSettings(this ICrashes operations, RetentionSettings retentionInDays, string ownerName, string appName) { return(operations.UpsertRetentionSettingsAsync(retentionInDays, ownerName, appName).GetAwaiter().GetResult()); }
/// <summary> /// Creates and updates the retention settings in days /// </summary> /// <remarks> /// Creates and updates the retention settings in days /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='retentionInDays'> /// The amount of days to keep the crashes for this application. /// retention_in_days is an enum value, can only be 28 or 90. /// </param> /// <param name='ownerName'> /// The name of the owner /// </param> /// <param name='appName'> /// The name of the application /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <RetentionSettings> UpsertRetentionSettingsAsync(this ICrashes operations, RetentionSettings retentionInDays, string ownerName, string appName, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpsertRetentionSettingsWithHttpMessagesAsync(retentionInDays, ownerName, appName, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }