From ea4333a13bb28a1bc0be5b60f408d895d3ee44d4 Mon Sep 17 00:00:00 2001 From: malik masis Date: Tue, 8 Mar 2022 10:40:59 +0300 Subject: [PATCH] Used IAbpDistributedLock instead of IDistributedLockProvider --- ...strationServiceDatabaseMigrationEventHandler.cs | 10 +++++----- .../CatalogServiceDatabaseMigrationEventHandler.cs | 14 +++++++------- ...IdentityServiceDatabaseMigrationEventHandler.cs | 5 +++-- ...OrderingServiceDatabaseMigrationEventHandler.cs | 6 +++--- .../PaymentServiceDatabaseMigrationEventHandler.cs | 12 ++++++------ .../EfCore/DatabaseEfCoreMigrationEventHandler.cs | 5 +++-- .../DatabaseMongoDbMigrationEventHandler.cs | 8 ++++---- 7 files changed, 31 insertions(+), 29 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 4df15ec5..a25acdb1 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/DbMigrations/AdministrationServiceDatabaseMigrationEventHandler.cs @@ -1,12 +1,12 @@ using EShopOnAbp.AdministrationService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Medallion.Threading; using Microsoft.Extensions.Logging; using System; using System.Linq; using System.Threading.Tasks; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement; @@ -29,7 +29,7 @@ namespace EShopOnAbp.AdministrationService.DbMigrations IPermissionDefinitionManager permissionDefinitionManager, IPermissionDataSeeder permissionDataSeeder, IDistributedEventBus distributedEventBus, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) : base( currentTenant, unitOfWorkManager, @@ -67,11 +67,11 @@ namespace EShopOnAbp.AdministrationService.DbMigrations { try { - Logger.LogInformation("AdministrationService - Before Acquire"); + Logger.LogInformation("AdministrationService - Before Acquire and Migration and Seed Data"); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { - if(handle != null) + if (handle != null) { await MigrateDatabaseSchemaAsync(eventData.Id); Logger.LogInformation("Starting AdministrationService DataSeeder..."); diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs index 1b513492..7c126a57 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/DbMigrations/CatalogServiceDatabaseMigrationEventHandler.cs @@ -1,10 +1,10 @@ -using System; -using System.Threading.Tasks; -using EShopOnAbp.CatalogService.MongoDB; +using EShopOnAbp.CatalogService.MongoDB; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb; -using Medallion.Threading; using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -21,7 +21,7 @@ namespace EShopOnAbp.CatalogService.DbMigrations ITenantStore tenantStore, IDistributedEventBus distributedEventBus, IServiceProvider serviceProvider, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) : base( currentTenant, unitOfWorkManager, @@ -47,9 +47,9 @@ namespace EShopOnAbp.CatalogService.DbMigrations try { - Logger.LogInformation("CatalogService - Before Acquire "); + Logger.LogInformation("CatalogService - Before Acquire and MigrateDatabaseSchemaAsync"); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { 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 00cdaade..726c51a1 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDatabaseMigrationEventHandler.cs @@ -12,6 +12,7 @@ using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; using Medallion.Threading; using Microsoft.Extensions.Logging; +using Volo.Abp.DistributedLocking; namespace EShopOnAbp.IdentityService.DbMigrations { @@ -32,7 +33,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations IdentityServerDataSeeder identityServerDataSeeder, IDistributedEventBus distributedEventBus, ILocalEventBus localEventBus, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) : base( currentTenant, unitOfWorkManager, @@ -57,7 +58,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations { Logger.LogInformation("IdentityService - Before Acquire "); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs index 1e32c00f..7804ec2c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/DbMigrations/OrderingServiceDatabaseMigrationEventHandler.cs @@ -1,10 +1,10 @@ using EShopOnAbp.OrderingService.EntityFrameworkCore; using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; -using Medallion.Threading; using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -23,7 +23,7 @@ namespace EShopOnAbp.OrderingService.DbMigrations ITenantStore tenantStore, IDistributedEventBus distributedEventBus, IDataSeeder dataSeeder, - IDistributedLockProvider distributedLockProvider) + IAbpDistributedLock distributedLockProvider) : base( currentTenant, unitOfWorkManager, @@ -53,7 +53,7 @@ namespace EShopOnAbp.OrderingService.DbMigrations { Logger.LogInformation("OrderingService - Before Acquire "); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs index 19f29057..a94fe4ff 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/DbMigrations/PaymentServiceDatabaseMigrationEventHandler.cs @@ -1,13 +1,13 @@ using EShopOnAbp.PaymentService.EntityFrameworkCore; +using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; +using Microsoft.Extensions.Logging; using System; 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.MultiTenancy; using Volo.Abp.Uow; -using Medallion.Threading; -using Microsoft.Extensions.Logging; namespace EShopOnAbp.PaymentService.DbMigrations { @@ -20,7 +20,7 @@ namespace EShopOnAbp.PaymentService.DbMigrations IUnitOfWorkManager unitOfWorkManager, ITenantStore tenantStore, IDistributedEventBus distributedEventBus, - IDistributedLockProvider distributedLockProvider) + IAbpDistributedLock distributedLockProvider) : base( currentTenant, unitOfWorkManager, @@ -45,9 +45,9 @@ namespace EShopOnAbp.PaymentService.DbMigrations try { - Logger.LogInformation("PaymentService - Before Acquire "); + Logger.LogInformation("PaymentService - Before Acquire and MigrateDatabaseSchemaAsync"); - await using (var handle = await DistributedLockProvider.AcquireLockAsync(DatabaseName)) + await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) { if (handle != null) { diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs index 1fd0d377..1180fa7c 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/EfCore/DatabaseEfCoreMigrationEventHandler.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Serilog; using Volo.Abp; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EventBus.Distributed; @@ -30,7 +31,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database protected IDistributedEventBus DistributedEventBus { get; } protected ILogger> Logger { get; set; } protected string DatabaseName { get; } - protected IDistributedLockProvider DistributedLockProvider { get; } + protected IAbpDistributedLock DistributedLockProvider { get; } protected DatabaseEfCoreMigrationEventHandler( ICurrentTenant currentTenant, @@ -38,7 +39,7 @@ public abstract class DatabaseEfCoreMigrationEventHandler : Database ITenantStore tenantStore, IDistributedEventBus distributedEventBus, string databaseName, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) { CurrentTenant = currentTenant; diff --git a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs index 251e6a92..18235262 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Microservices/DbMigrations/MongoDb/DatabaseMongoDbMigrationEventHandler.cs @@ -1,5 +1,4 @@ -using Medallion.Threading; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using MongoDB.Driver; @@ -8,6 +7,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Data; +using Volo.Abp.DistributedLocking; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.EventBus.Distributed; using Volo.Abp.MongoDB; @@ -29,7 +29,7 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas protected ILogger> Logger { get; set; } protected IServiceProvider ServiceProvider { get; } protected string DatabaseName { get; } - protected IDistributedLockProvider DistributedLockProvider { get; } + protected IAbpDistributedLock DistributedLockProvider { get; } protected DatabaseMongoDbMigrationEventHandler( @@ -39,7 +39,7 @@ public abstract class DatabaseMongoDbMigrationEventHandler : Databas IDistributedEventBus distributedEventBus, string databaseName, IServiceProvider serviceProvider, - IDistributedLockProvider distributedLockProvider + IAbpDistributedLock distributedLockProvider ) { CurrentTenant = currentTenant;