From 05f34f73cdf09af0c7e3ffc5cfd57882d2474e2b Mon Sep 17 00:00:00 2001 From: Fredi Kats Date: Sat, 17 Sep 2022 14:01:27 +0400 Subject: [PATCH 1/2] refactor: extract table worker to separated project --- .../ConcurrentHashSet.cs | 2 +- .../GoogleTableUpdateWorker.cs | 12 ++++++------ .../ITableAccessor.cs | 7 +++++++ ...t.Shreks.Application.TableManagement.csproj | 18 ++++++++++++++++++ .../TableUpdateQueue.cs | 3 +-- .../Extensions/ServiceCollectionExtensions.cs | 3 ++- .../GoogleTableAccessor.cs | 3 ++- .../Kysect.Shreks.Integration.Google.csproj | 4 ++-- .../Controllers/GoogleController.cs | 3 ++- Source/Kysect.Shreks.sln | 7 +++++++ .../Kysect.Shreks.Playground.Google/Program.cs | 1 + .../UpdateSubmissionStateHandlerTest.cs | 1 + 12 files changed, 50 insertions(+), 14 deletions(-) rename Source/{Infrastructure/Integration/Kysect.Shreks.Integration.Google/Models => Application/Kysect.Shreks.Application.TableManagement}/ConcurrentHashSet.cs (89%) rename Source/{Infrastructure/Integration/Kysect.Shreks.Integration.Google => Application/Kysect.Shreks.Application.TableManagement}/GoogleTableUpdateWorker.cs (86%) create mode 100644 Source/Application/Kysect.Shreks.Application.TableManagement/ITableAccessor.cs create mode 100644 Source/Application/Kysect.Shreks.Application.TableManagement/Kysect.Shreks.Application.TableManagement.csproj rename Source/{Infrastructure/Integration/Kysect.Shreks.Integration.Google => Application/Kysect.Shreks.Application.TableManagement}/TableUpdateQueue.cs (89%) diff --git a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Models/ConcurrentHashSet.cs b/Source/Application/Kysect.Shreks.Application.TableManagement/ConcurrentHashSet.cs similarity index 89% rename from Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Models/ConcurrentHashSet.cs rename to Source/Application/Kysect.Shreks.Application.TableManagement/ConcurrentHashSet.cs index 84b8debf3..918f4c335 100644 --- a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Models/ConcurrentHashSet.cs +++ b/Source/Application/Kysect.Shreks.Application.TableManagement/ConcurrentHashSet.cs @@ -1,4 +1,4 @@ -namespace Kysect.Shreks.Integration.Google.Models; +namespace Kysect.Shreks.Application.TableManagement; public class ConcurrentHashSet { diff --git a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableUpdateWorker.cs b/Source/Application/Kysect.Shreks.Application.TableManagement/GoogleTableUpdateWorker.cs similarity index 86% rename from Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableUpdateWorker.cs rename to Source/Application/Kysect.Shreks.Application.TableManagement/GoogleTableUpdateWorker.cs index b6b26982e..66ac100f3 100644 --- a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableUpdateWorker.cs +++ b/Source/Application/Kysect.Shreks.Application.TableManagement/GoogleTableUpdateWorker.cs @@ -1,9 +1,9 @@ -using System.Diagnostics; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using System.Diagnostics; -namespace Kysect.Shreks.Integration.Google; +namespace Kysect.Shreks.Application.TableManagement; public class GoogleTableUpdateWorker : BackgroundService { @@ -31,7 +31,7 @@ protected override async Task ExecuteAsync(CancellationToken token) while (!token.IsCancellationRequested && await timer.WaitForNextTickAsync(token)) { using IServiceScope serviceScope = _serviceProvider.CreateScope(); - using var googleTableAccessor = serviceScope.ServiceProvider.GetRequiredService(); + using var googleTableAccessor = serviceScope.ServiceProvider.GetRequiredService(); _stopwatch.Restart(); @@ -45,7 +45,7 @@ protected override async Task ExecuteAsync(CancellationToken token) } } - private async Task UpdateTablePoints(GoogleTableAccessor googleTableAccessor, CancellationToken token) + private async Task UpdateTablePoints(ITableAccessor googleTableAccessor, CancellationToken token) { IReadOnlyCollection points = _tableUpdateQueue .PointsUpdateSubjectCourseIds @@ -60,7 +60,7 @@ private async Task UpdateTablePoints(GoogleTableAccessor googleTableAccess return points.Any(); } - private async Task UpdateTableQueue(GoogleTableAccessor googleTableAccessor, CancellationToken token) + private async Task UpdateTableQueue(ITableAccessor googleTableAccessor, CancellationToken token) { IReadOnlyCollection<(Guid, Guid)> queues = _tableUpdateQueue .QueueUpdateSubjectCourseGroupIds diff --git a/Source/Application/Kysect.Shreks.Application.TableManagement/ITableAccessor.cs b/Source/Application/Kysect.Shreks.Application.TableManagement/ITableAccessor.cs new file mode 100644 index 000000000..296a899db --- /dev/null +++ b/Source/Application/Kysect.Shreks.Application.TableManagement/ITableAccessor.cs @@ -0,0 +1,7 @@ +namespace Kysect.Shreks.Application.TableManagement; + +public interface ITableAccessor : IDisposable +{ + Task UpdatePointsAsync(Guid subjectCourseId, CancellationToken token); + Task UpdateQueueAsync(Guid subjectCourseId, Guid studentGroupId, CancellationToken token); +} \ No newline at end of file diff --git a/Source/Application/Kysect.Shreks.Application.TableManagement/Kysect.Shreks.Application.TableManagement.csproj b/Source/Application/Kysect.Shreks.Application.TableManagement/Kysect.Shreks.Application.TableManagement.csproj new file mode 100644 index 000000000..34b88c444 --- /dev/null +++ b/Source/Application/Kysect.Shreks.Application.TableManagement/Kysect.Shreks.Application.TableManagement.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/TableUpdateQueue.cs b/Source/Application/Kysect.Shreks.Application.TableManagement/TableUpdateQueue.cs similarity index 89% rename from Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/TableUpdateQueue.cs rename to Source/Application/Kysect.Shreks.Application.TableManagement/TableUpdateQueue.cs index 8ab085d46..85c7d9fc9 100644 --- a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/TableUpdateQueue.cs +++ b/Source/Application/Kysect.Shreks.Application.TableManagement/TableUpdateQueue.cs @@ -1,7 +1,6 @@ using Kysect.Shreks.Application.Abstractions.Google; -using Kysect.Shreks.Integration.Google.Models; -namespace Kysect.Shreks.Integration.Google; +namespace Kysect.Shreks.Application.TableManagement; public class TableUpdateQueue : ITableUpdateQueue { diff --git a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Extensions/ServiceCollectionExtensions.cs b/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Extensions/ServiceCollectionExtensions.cs index f919c2ac3..bcd3e128c 100644 --- a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Extensions/ServiceCollectionExtensions.cs +++ b/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Extensions/ServiceCollectionExtensions.cs @@ -5,6 +5,7 @@ using Kysect.Shreks.Application.Abstractions.Formatters; using Kysect.Shreks.Application.Abstractions.Google; using Kysect.Shreks.Application.Dto.Tables; +using Kysect.Shreks.Application.TableManagement; using Kysect.Shreks.Integration.Google.Options; using Kysect.Shreks.Integration.Google.Providers; using Kysect.Shreks.Integration.Google.Sheets; @@ -56,7 +57,7 @@ private static IServiceCollection AddGoogleTableUpdateWorker(this IServiceCollec return serviceCollection .AddSingleton() .AddSingleton(p => p.GetRequiredService()) - .AddScoped() + .AddScoped() .AddHostedService(); } diff --git a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableAccessor.cs b/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableAccessor.cs index 4f7d5ae54..fdbd5469d 100644 --- a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableAccessor.cs +++ b/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/GoogleTableAccessor.cs @@ -1,6 +1,7 @@ using Kysect.Shreks.Application.Abstractions.Google.Commands; using Kysect.Shreks.Application.Abstractions.Google.Queries; using Kysect.Shreks.Application.Dto.Tables; +using Kysect.Shreks.Application.TableManagement; using Kysect.Shreks.Integration.Google.Sheets; using Kysect.Shreks.Integration.Google.Tools; using MediatR; @@ -8,7 +9,7 @@ namespace Kysect.Shreks.Integration.Google; -public class GoogleTableAccessor : IDisposable +public class GoogleTableAccessor : ITableAccessor { private readonly SemaphoreSlim _spreadsheetCreationSemaphore; diff --git a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Kysect.Shreks.Integration.Google.csproj b/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Kysect.Shreks.Integration.Google.csproj index f9302fe30..929369d09 100644 --- a/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Kysect.Shreks.Integration.Google.csproj +++ b/Source/Infrastructure/Integration/Kysect.Shreks.Integration.Google/Kysect.Shreks.Integration.Google.csproj @@ -17,8 +17,8 @@ - + + \ No newline at end of file diff --git a/Source/Kysect.Shreks.WebApi/Controllers/GoogleController.cs b/Source/Kysect.Shreks.WebApi/Controllers/GoogleController.cs index 32c638511..f64d4b5f6 100644 --- a/Source/Kysect.Shreks.WebApi/Controllers/GoogleController.cs +++ b/Source/Kysect.Shreks.WebApi/Controllers/GoogleController.cs @@ -1,4 +1,5 @@ -using Kysect.Shreks.Integration.Google; +using Kysect.Shreks.Application.TableManagement; +using Kysect.Shreks.Integration.Google; using Microsoft.AspNetCore.Mvc; namespace Kysect.Shreks.WebApi.Controllers diff --git a/Source/Kysect.Shreks.sln b/Source/Kysect.Shreks.sln index 419558233..682bb2eda 100644 --- a/Source/Kysect.Shreks.sln +++ b/Source/Kysect.Shreks.sln @@ -68,6 +68,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kysect.Shreks.Application.TableManagement", "Application\Kysect.Shreks.Application.TableManagement\Kysect.Shreks.Application.TableManagement.csproj", "{A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -166,6 +168,10 @@ Global {3B0EB40E-6E3C-4F8D-BBD7-9B7FC5FB7D68}.Debug|Any CPU.Build.0 = Debug|Any CPU {3B0EB40E-6E3C-4F8D-BBD7-9B7FC5FB7D68}.Release|Any CPU.ActiveCfg = Release|Any CPU {3B0EB40E-6E3C-4F8D-BBD7-9B7FC5FB7D68}.Release|Any CPU.Build.0 = Release|Any CPU + {A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A57B6F3D-1DC1-41A7-90CD-99158B4D55DA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -195,6 +201,7 @@ Global {601BCCAB-8895-43CB-BC46-EE2C20F4031F} = {DC866D57-D41E-455D-BD7D-85F1DD575823} {DF0C2310-8F92-404C-885E-D495B3F334EB} = {AE556858-2A9D-481F-9235-3C74F0CDC5A5} {3B0EB40E-6E3C-4F8D-BBD7-9B7FC5FB7D68} = {AE556858-2A9D-481F-9235-3C74F0CDC5A5} + {A57B6F3D-1DC1-41A7-90CD-99158B4D55DA} = {AE556858-2A9D-481F-9235-3C74F0CDC5A5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {CD5C67DB-70F8-4C47-A3F4-7C94BECE1657} diff --git a/Source/Playground/Kysect.Shreks.Playground.Google/Program.cs b/Source/Playground/Kysect.Shreks.Playground.Google/Program.cs index c92721ca5..ed0cc99ee 100644 --- a/Source/Playground/Kysect.Shreks.Playground.Google/Program.cs +++ b/Source/Playground/Kysect.Shreks.Playground.Google/Program.cs @@ -2,6 +2,7 @@ using Google.Apis.Auth.OAuth2; using Kysect.Shreks.Application.Abstractions.Google; using Kysect.Shreks.Application.Extensions; +using Kysect.Shreks.Application.TableManagement; using Kysect.Shreks.DataAccess.Context; using Kysect.Shreks.Integration.Google; using Kysect.Shreks.Integration.Google.Extensions; diff --git a/Source/Tests/Kysect.Shreks.Tests/Application/UpdateSubmissionStateHandlerTest.cs b/Source/Tests/Kysect.Shreks.Tests/Application/UpdateSubmissionStateHandlerTest.cs index 48b267e4e..5416a96ab 100644 --- a/Source/Tests/Kysect.Shreks.Tests/Application/UpdateSubmissionStateHandlerTest.cs +++ b/Source/Tests/Kysect.Shreks.Tests/Application/UpdateSubmissionStateHandlerTest.cs @@ -1,5 +1,6 @@ using FluentAssertions; using Kysect.Shreks.Application.Commands.Processors; +using Kysect.Shreks.Application.TableManagement; using Kysect.Shreks.Core.Models; using Kysect.Shreks.Core.Submissions; using Kysect.Shreks.Integration.Google; From 8f4892af3d1dc636d4174f3f07386df51059890c Mon Sep 17 00:00:00 2001 From: Fredi Kats Date: Sat, 17 Sep 2022 14:03:15 +0400 Subject: [PATCH 2/2] feat: add new project to docker config --- Docker/build.dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Docker/build.dockerfile b/Docker/build.dockerfile index 999c4ba22..678ba0436 100644 --- a/Docker/build.dockerfile +++ b/Docker/build.dockerfile @@ -13,6 +13,7 @@ COPY ./Application/Kysect.Shreks.DataAccess.Abstractions/Kysect.Shreks.DataAcces COPY ./Application/Kysect.Shreks.Application.Abstractions/Kysect.Shreks.Application.Abstractions.csproj ./Application/Kysect.Shreks.Application.Abstractions/Kysect.Shreks.Application.Abstractions.csproj COPY ./Application/Kysect.Shreks.Application/Kysect.Shreks.Application.csproj ./Application/Kysect.Shreks.Application/Kysect.Shreks.Application.csproj COPY ./Application/Kysect.Shreks.Application.Dto/Kysect.Shreks.Application.Dto.csproj ./Application/Kysect.Shreks.Application.Dto/Kysect.Shreks.Application.Dto.csproj +COPY ./Application/Kysect.Shreks.Application.TableManagement/Kysect.Shreks.Application.TableManagement.csproj ./Application/Kysect.Shreks.Application.TableManagement/Kysect.Shreks.Application.TableManagement.csproj COPY ./Infrastructure/Kysect.Shreks.Seeding/Kysect.Shreks.Seeding.csproj ./Infrastructure/Kysect.Shreks.Seeding/Kysect.Shreks.Seeding.csproj COPY ./Infrastructure/Integration/Kysect.Shreks.Integration.Github/Kysect.Shreks.Integration.Github.csproj ./Infrastructure/Integration/Kysect.Shreks.Integration.Github/Kysect.Shreks.Integration.Github.csproj COPY ./Infrastructure/Integration/Kysect.Shreks.Integration.Google/Kysect.Shreks.Integration.Google.csproj ./Infrastructure/Integration/Kysect.Shreks.Integration.Google/Kysect.Shreks.Integration.Google.csproj