-
-
Notifications
You must be signed in to change notification settings - Fork 508
Add project notification settings maintenance cleanup #2145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3094ff4
Add project notification settings maintenance cleanup
niemyjski d28eda7
Fix organization cleanup review feedback
niemyjski b695414
Revert cleanup notes from agents
niemyjski 1233c77
Merge branch 'main' into bugfix/user-notification-cleanup
niemyjski 8402edd
Merge branch 'main' into bugfix/user-notification-cleanup
niemyjski efa1af1
Merge branch 'main' into bugfix/user-notification-cleanup
niemyjski 4fddf6a
Refine notification cleanup logic and update agent skills
niemyjski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...eptionless.Core/Jobs/WorkItemHandlers/UpdateProjectNotificationSettingsWorkItemHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| using Exceptionless.Core.Models.WorkItems; | ||
| using Exceptionless.Core.Repositories; | ||
| using Exceptionless.Core.Services; | ||
| using Foundatio.Jobs; | ||
| using Foundatio.Lock; | ||
| using Foundatio.Repositories; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Exceptionless.Core.Jobs.WorkItemHandlers; | ||
|
|
||
| public class UpdateProjectNotificationSettingsWorkItemHandler : WorkItemHandlerBase | ||
| { | ||
| private const int BATCH_SIZE = 50; | ||
|
|
||
| private readonly IOrganizationRepository _organizationRepository; | ||
| private readonly OrganizationService _organizationService; | ||
| private readonly ILockProvider _lockProvider; | ||
| private readonly TimeProvider _timeProvider; | ||
|
|
||
| public UpdateProjectNotificationSettingsWorkItemHandler( | ||
| IOrganizationRepository organizationRepository, | ||
| OrganizationService organizationService, | ||
| ILockProvider lockProvider, | ||
| TimeProvider timeProvider, | ||
| ILoggerFactory loggerFactory) : base(loggerFactory) | ||
| { | ||
| _organizationRepository = organizationRepository; | ||
| _organizationService = organizationService; | ||
| _lockProvider = lockProvider; | ||
| _timeProvider = timeProvider; | ||
| } | ||
|
|
||
| public override Task<ILock> GetWorkItemLockAsync(object workItem, CancellationToken cancellationToken = new()) | ||
| { | ||
| return _lockProvider.AcquireAsync(nameof(UpdateProjectNotificationSettingsWorkItemHandler), TimeSpan.FromMinutes(15), cancellationToken); | ||
| } | ||
|
|
||
| public override async Task HandleItemAsync(WorkItemContext context) | ||
| { | ||
| var workItem = context.GetData<UpdateProjectNotificationSettingsWorkItem>(); | ||
| Log.LogInformation("Received update project notification settings work item. Organization={Organization}", workItem.OrganizationId); | ||
|
|
||
| long totalNotificationSettingsRemoved = 0; | ||
| long organizationsProcessed = 0; | ||
|
|
||
| if (!String.IsNullOrEmpty(workItem.OrganizationId)) | ||
| { | ||
| await context.ReportProgressAsync(0, $"Starting project notification settings update for organization {workItem.OrganizationId}"); | ||
|
|
||
| var organization = await _organizationRepository.GetByIdAsync(workItem.OrganizationId); | ||
| if (organization is null) | ||
| { | ||
| Log.LogWarning("Organization {Organization} not found", workItem.OrganizationId); | ||
| return; | ||
| } | ||
|
|
||
| totalNotificationSettingsRemoved += await _organizationService.CleanupProjectNotificationSettingsAsync( | ||
| organization, | ||
| [], | ||
| context.CancellationToken, | ||
| context.RenewLockAsync); | ||
| organizationsProcessed++; | ||
| } | ||
| else | ||
| { | ||
| await context.ReportProgressAsync(0, "Starting project notification settings update for all organizations"); | ||
|
|
||
| var results = await _organizationRepository.FindAsync( | ||
| q => q.Include(o => o.Id), | ||
| o => o.SearchAfterPaging().PageLimit(BATCH_SIZE)); | ||
|
|
||
| long totalOrganizations = results.Total; | ||
|
|
||
| while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested) | ||
| { | ||
| foreach (var organization in results.Documents) | ||
| { | ||
| totalNotificationSettingsRemoved += await _organizationService.CleanupProjectNotificationSettingsAsync( | ||
| organization, | ||
| [], | ||
| context.CancellationToken, | ||
| context.RenewLockAsync); | ||
| organizationsProcessed++; | ||
| } | ||
|
|
||
| int percentage = totalOrganizations > 0 | ||
| ? (int)Math.Min(99, organizationsProcessed * 100.0 / totalOrganizations) | ||
| : 99; | ||
| await context.ReportProgressAsync(percentage, $"Processed {organizationsProcessed}/{totalOrganizations} organizations, removed {totalNotificationSettingsRemoved} invalid notification settings"); | ||
|
|
||
| await Task.Delay(TimeSpan.FromSeconds(2.5), _timeProvider); | ||
|
|
||
| if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync()) | ||
| break; | ||
|
|
||
| if (results.Documents.Count > 0) | ||
| await context.RenewLockAsync(); | ||
| } | ||
| } | ||
|
|
||
| Log.LogInformation("Project notification settings update complete. Organizations processed: {OrganizationsProcessed}, invalid notification settings removed: {RemovedNotificationSettings}", organizationsProcessed, totalNotificationSettingsRemoved); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/Exceptionless.Core/Models/WorkItems/UpdateProjectNotificationSettingsWorkItem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Exceptionless.Core.Models.WorkItems; | ||
|
|
||
| public record UpdateProjectNotificationSettingsWorkItem | ||
| { | ||
| public string? OrganizationId { get; init; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.