From bd67b9563c545ecf487d406ac30ae65e61eb5e02 Mon Sep 17 00:00:00 2001 From: malik masis Date: Fri, 11 Mar 2022 12:33:30 +0300 Subject: [PATCH] Removed TenantCreatedEto handling Removed TenantCreatedEto handling from - Administration - IdentityService --- ...ionServiceDatabaseMigrationEventHandler.cs | 18 +------------- ...ityServiceDatabaseMigrationEventHandler.cs | 24 +++---------------- .../DatabaseEfCoreMigrationEventHandler.cs | 22 ----------------- .../DatabaseMongoDbMigrationEventHandler.cs | 22 ----------------- 4 files changed, 4 insertions(+), 82 deletions(-) diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs index 2fb26184..a0dffc9e 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs @@ -1,10 +1,9 @@ using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Microsoft.Extensions.Logging; +using Serilog; using System; using System.Linq; using System.Threading.Tasks; -using Serilog; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Data; using Volo.Abp.DistributedLocking; @@ -17,7 +16,6 @@ namespace EShopOnAbp.AdministrationService.DbMigrations { public class AdministrationServiceDatabaseMigrationEventHandler : DatabaseEfCoreMigrationEventHandler, - IDistributedEventHandler, IDistributedEventHandler { private readonly IPermissionDefinitionManager _permissionDefinitionManager; @@ -70,20 +68,6 @@ namespace EShopOnAbp.AdministrationService.DbMigrations } } - public async Task HandleEventAsync(TenantCreatedEto eventData) - { - try - { - await MigrateDatabaseSchemaAsync(eventData.Id); - Logger.LogInformation("Starting AdministrationService DataSeeder..."); - await SeedDataAsync(eventData.Id); - } - catch (Exception ex) - { - await HandleErrorTenantCreatedAsync(eventData, ex); - } - } - private async Task SeedDataAsync(Guid? tenantId) { using (CurrentTenant.Change(tenantId)) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs index 71c99268..7b7c1cf0 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs @@ -1,22 +1,20 @@ using EShopOnAbp.IdentityService.EntityFrameworkCore; +using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; using Serilog; using System; -using System.Collections.Generic; using System.Threading.Tasks; -using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Local; using Volo.Abp.Identity; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; -using Volo.Abp.DistributedLocking; namespace EShopOnAbp.IdentityService.DbMigrations { public class IdentityServiceDatabaseMigrationEventHandler : DatabaseEfCoreMigrationEventHandler, - IDistributedEventHandler, IDistributedEventHandler { private readonly IIdentityDataSeeder _identityDataSeeder; @@ -57,7 +55,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { Log.Information("IdentityService has acquired lock for db migration..."); - + if (handle != null) { Log.Information("IdentityService is migrating database..."); @@ -79,22 +77,6 @@ namespace EShopOnAbp.IdentityService.DbMigrations } } - public async Task HandleEventAsync(TenantCreatedEto eventData) - { - try - { - await MigrateDatabaseSchemaAsync(eventData.Id); - await SeedDataAsync( - tenantId: eventData.Id, - adminEmail: eventData.Properties.GetOrDefault(IdentityDataSeedContributor.AdminEmailPropertyName) ?? IdentityServiceDbProperties.DefaultAdminEmailAddress, - adminPassword: eventData.Properties.GetOrDefault(IdentityDataSeedContributor.AdminPasswordPropertyName) ?? IdentityServiceDbProperties.DefaultAdminPassword - ); - } - catch (Exception ex) - { - await HandleErrorTenantCreatedAsync(eventData, ex); - } - } private async Task SeedDataAsync(Guid? tenantId, string adminEmail, string adminPassword) { using (CurrentTenant.Change(tenantId)) diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs index d35f2b91..69f34f4a 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs @@ -127,28 +127,6 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database } } - protected virtual async Task HandleErrorTenantCreatedAsync( - TenantCreatedEto eventData, - Exception exception) - { - var tryCount = IncrementEventTryCount(eventData); - if (tryCount <= MaxEventTryCount) - { - Log.Warning( - $"Could not perform tenant created event. Re-queueing the operation. TenantId = {eventData.Id}, TenantName = {eventData.Name}."); - Logger.LogException(exception, LogLevel.Warning); - - await Task.Delay(RandomHelper.GetRandom(5000, 15000)); - await DistributedEventBus.PublishAsync(eventData); - } - else - { - Logger.LogError( - $"Could not perform tenant created event. Canceling the operation. TenantId = {eventData.Id}, TenantName = {eventData.Name}."); - Logger.LogException(exception); - } - } - protected virtual async Task HandleErrorTenantConnectionStringUpdatedAsync( TenantConnectionStringUpdatedEto eventData, Exception exception) diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs index 18235262..282a648e 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs @@ -140,28 +140,6 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas } } - protected virtual async Task HandleErrorTenantCreatedAsync( - TenantCreatedEto eventData, - Exception exception) - { - var tryCount = IncrementEventTryCount(eventData); - if (tryCount <= MaxEventTryCount) - { - Logger.LogWarning( - $"Could not perform tenant created event. Re-queueing the operation. TenantId = {eventData.Id}, TenantName = {eventData.Name}."); - Logger.LogException(exception, LogLevel.Warning); - - await Task.Delay(RandomHelper.GetRandom(5000, 15000)); - await DistributedEventBus.PublishAsync(eventData); - } - else - { - Logger.LogError( - $"Could not perform tenant created event. Canceling the operation. TenantId = {eventData.Id}, TenantName = {eventData.Name}."); - Logger.LogException(exception); - } - } - protected virtual async Task HandleErrorTenantConnectionStringUpdatedAsync( TenantConnectionStringUpdatedEto eventData, Exception exception)