Browse Source

Merge branch 'dev' into studio-dev

pull/10363/head
Yunus Emre Kalkan 4 years ago
parent
commit
d593845b07
  1. 21
      framework/Volo.Abp.sln
  2. 2
      framework/src/Volo.Abp.BackgroundJobs/Volo.Abp.BackgroundJobs.csproj
  3. 4
      framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobsModule.cs
  4. 103
      framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs
  5. 11
      framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerBase.cs
  6. 2
      framework/src/Volo.Abp.Ddd.Domain/Volo.Abp.Ddd.Domain.csproj
  7. 2
      framework/src/Volo.Abp.Ddd.Domain/Volo.Abp.Ddd.Domain.csproj.DotSettings
  8. 3
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/AbpDddDomainModule.cs
  9. 3
      framework/src/Volo.Abp.DistributedLocking.Abstractions/FodyWeavers.xml
  10. 2
      framework/src/Volo.Abp.DistributedLocking.Abstractions/FodyWeavers.xsd
  11. 8
      framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo.Abp.DistributedLocking.Abstractions.csproj
  12. 9
      framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/AbpDistributedLockingAbstractionsModule.cs
  13. 26
      framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/IAbpDistributedLock.cs
  14. 9
      framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/IAbpDistributedLockHandle.cs
  15. 30
      framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/LocalAbpDistributedLock.cs
  16. 21
      framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/LocalAbpDistributedLockHandle.cs
  17. 2
      framework/src/Volo.Abp.DistributedLocking/Volo.Abp.DistributedLocking.csproj
  18. 14
      framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/AbpDistributedLockHandleExtensions.cs
  19. 3
      framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/AbpDistributedLockingModule.cs
  20. 35
      framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/MedallionAbpDistributedLock.cs
  21. 20
      framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/MedallionAbpDistributedLockHandle.cs
  22. 3
      framework/src/Volo.Abp.EventBus.Boxes/FodyWeavers.xml
  23. 20
      framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/AbpEventBusBoxesModule.cs
  24. 20
      framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/TaskHelper.cs
  25. 2
      framework/src/Volo.Abp.EventBus/Volo.Abp.EventBus.csproj
  26. 13
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/AbpEventBusModule.cs
  27. 0
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/AbpDistributedEventBusExtensions.cs
  28. 0
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/AbpEventBusBoxesOptions.cs
  29. 0
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IInboxProcessor.cs
  30. 0
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IOutboxSender.cs
  31. 0
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessManager.cs
  32. 20
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs
  33. 22
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs
  34. 0
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSenderManager.cs
  35. 3
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs
  36. 18
      framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo.Abp.DistributedLocking.Abstractions.Tests.csproj
  37. 12
      framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo/Abp/DistributedLocking/AbpDistributedLockingAbstractionsTestBase.cs
  38. 15
      framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo/Abp/DistributedLocking/AbpDistributedLockingAbstractionsTestModule.cs
  39. 73
      framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo/Abp/DistributedLocking/LocalDistributedLock_Tests.cs
  40. 4
      modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs
  41. 2
      nupkg/common.ps1
  42. 4
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/global.css
  43. 4
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html
  44. 4
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/wwwroot/global.css
  45. 2
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/wwwroot/global.js
  46. 4
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/wwwroot/index.html

21
framework/Volo.Abp.sln

@ -391,14 +391,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.IdentityModel.Test
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Threading.Tests", "test\Volo.Abp.Threading.Tests\Volo.Abp.Threading.Tests.csproj", "{7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Threading.Tests", "test\Volo.Abp.Threading.Tests\Volo.Abp.Threading.Tests.csproj", "{7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.EventBus.Boxes", "src\Volo.Abp.EventBus.Boxes\Volo.Abp.EventBus.Boxes.csproj", "{6E289F31-7924-418B-9DAC-62A7CFADF916}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.DistributedLocking", "src\Volo.Abp.DistributedLocking\Volo.Abp.DistributedLocking.csproj", "{9A7EEA08-15BE-476D-8168-53039867038E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.DistributedLocking", "src\Volo.Abp.DistributedLocking\Volo.Abp.DistributedLocking.csproj", "{9A7EEA08-15BE-476D-8168-53039867038E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Auditing.Contracts", "src\Volo.Abp.Auditing.Contracts\Volo.Abp.Auditing.Contracts.csproj", "{508B6355-AD28-4E60-8549-266D21DBF2CF}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Auditing.Contracts", "src\Volo.Abp.Auditing.Contracts\Volo.Abp.Auditing.Contracts.csproj", "{508B6355-AD28-4E60-8549-266D21DBF2CF}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Client.Web", "src\Volo.Abp.Http.Client.Web\Volo.Abp.Http.Client.Web.csproj", "{F7407459-8AFA-45E4-83E9-9BB01412CC08}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Client.Web", "src\Volo.Abp.Http.Client.Web\Volo.Abp.Http.Client.Web.csproj", "{F7407459-8AFA-45E4-83E9-9BB01412CC08}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.DistributedLocking.Abstractions", "src\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj", "{CA805B77-D50C-431F-B3CB-1111C9C6E807}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.DistributedLocking.Abstractions.Tests", "test\Volo.Abp.DistributedLocking.Abstractions.Tests\Volo.Abp.DistributedLocking.Abstractions.Tests.csproj", "{C4F54FB5-C828-414D-BA03-E8E7A10C784D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundWorkers.Hangfire", "src\Volo.Abp.BackgroundWorkers.Hangfire\Volo.Abp.BackgroundWorkers.Hangfire.csproj", "{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundWorkers.Hangfire", "src\Volo.Abp.BackgroundWorkers.Hangfire\Volo.Abp.BackgroundWorkers.Hangfire.csproj", "{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}"
EndProject EndProject
Global Global
@ -1175,10 +1177,6 @@ Global
{7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}.Release|Any CPU.Build.0 = Release|Any CPU {7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B}.Release|Any CPU.Build.0 = Release|Any CPU
{6E289F31-7924-418B-9DAC-62A7CFADF916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E289F31-7924-418B-9DAC-62A7CFADF916}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E289F31-7924-418B-9DAC-62A7CFADF916}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E289F31-7924-418B-9DAC-62A7CFADF916}.Release|Any CPU.Build.0 = Release|Any CPU
{9A7EEA08-15BE-476D-8168-53039867038E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9A7EEA08-15BE-476D-8168-53039867038E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A7EEA08-15BE-476D-8168-53039867038E}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A7EEA08-15BE-476D-8168-53039867038E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A7EEA08-15BE-476D-8168-53039867038E}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A7EEA08-15BE-476D-8168-53039867038E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -1191,6 +1189,14 @@ Global
{F7407459-8AFA-45E4-83E9-9BB01412CC08}.Debug|Any CPU.Build.0 = Debug|Any CPU {F7407459-8AFA-45E4-83E9-9BB01412CC08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7407459-8AFA-45E4-83E9-9BB01412CC08}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7407459-8AFA-45E4-83E9-9BB01412CC08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7407459-8AFA-45E4-83E9-9BB01412CC08}.Release|Any CPU.Build.0 = Release|Any CPU {F7407459-8AFA-45E4-83E9-9BB01412CC08}.Release|Any CPU.Build.0 = Release|Any CPU
{CA805B77-D50C-431F-B3CB-1111C9C6E807}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA805B77-D50C-431F-B3CB-1111C9C6E807}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA805B77-D50C-431F-B3CB-1111C9C6E807}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA805B77-D50C-431F-B3CB-1111C9C6E807}.Release|Any CPU.Build.0 = Release|Any CPU
{C4F54FB5-C828-414D-BA03-E8E7A10C784D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4F54FB5-C828-414D-BA03-E8E7A10C784D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4F54FB5-C828-414D-BA03-E8E7A10C784D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4F54FB5-C828-414D-BA03-E8E7A10C784D}.Release|Any CPU.Build.0 = Release|Any CPU
{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU {E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU {E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -1392,10 +1398,11 @@ Global
{90B1866A-EF99-40B9-970E-B898E5AA523F} = {447C8A77-E5F0-4538-8687-7383196D04EA} {90B1866A-EF99-40B9-970E-B898E5AA523F} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{40C6740E-BFCA-4D37-8344-3D84E2044BB2} = {447C8A77-E5F0-4538-8687-7383196D04EA} {40C6740E-BFCA-4D37-8344-3D84E2044BB2} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B} = {447C8A77-E5F0-4538-8687-7383196D04EA} {7B2FCAD6-86E6-49C8-ADBE-A61B4F4B101B} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{6E289F31-7924-418B-9DAC-62A7CFADF916} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{9A7EEA08-15BE-476D-8168-53039867038E} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {9A7EEA08-15BE-476D-8168-53039867038E} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{508B6355-AD28-4E60-8549-266D21DBF2CF} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {508B6355-AD28-4E60-8549-266D21DBF2CF} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{F7407459-8AFA-45E4-83E9-9BB01412CC08} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {F7407459-8AFA-45E4-83E9-9BB01412CC08} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{CA805B77-D50C-431F-B3CB-1111C9C6E807} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{C4F54FB5-C828-414D-BA03-E8E7A10C784D} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution

2
framework/src/Volo.Abp.BackgroundJobs/Volo.Abp.BackgroundJobs.csproj

@ -17,7 +17,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.BackgroundJobs.Abstractions\Volo.Abp.BackgroundJobs.Abstractions.csproj" /> <ProjectReference Include="..\Volo.Abp.BackgroundJobs.Abstractions\Volo.Abp.BackgroundJobs.Abstractions.csproj" />
<ProjectReference Include="..\Volo.Abp.BackgroundWorkers\Volo.Abp.BackgroundWorkers.csproj" /> <ProjectReference Include="..\Volo.Abp.BackgroundWorkers\Volo.Abp.BackgroundWorkers.csproj" />
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" /> <ProjectReference Include="..\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj" />
<ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" /> <ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" />
<ProjectReference Include="..\Volo.Abp.Timing\Volo.Abp.Timing.csproj" /> <ProjectReference Include="..\Volo.Abp.Timing\Volo.Abp.Timing.csproj" />
</ItemGroup> </ItemGroup>

4
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobsModule.cs

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.BackgroundWorkers; using Volo.Abp.BackgroundWorkers;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Timing; using Volo.Abp.Timing;
@ -11,7 +12,8 @@ namespace Volo.Abp.BackgroundJobs
typeof(AbpBackgroundJobsAbstractionsModule), typeof(AbpBackgroundJobsAbstractionsModule),
typeof(AbpBackgroundWorkersModule), typeof(AbpBackgroundWorkersModule),
typeof(AbpTimingModule), typeof(AbpTimingModule),
typeof(AbpGuidsModule) typeof(AbpGuidsModule),
typeof(AbpDistributedLockingAbstractionsModule)
)] )]
public class AbpBackgroundJobsModule : AbpModule public class AbpBackgroundJobsModule : AbpModule
{ {

103
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs

@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.BackgroundWorkers; using Volo.Abp.BackgroundWorkers;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Timing; using Volo.Abp.Timing;
@ -12,19 +13,25 @@ namespace Volo.Abp.BackgroundJobs
{ {
public class BackgroundJobWorker : AsyncPeriodicBackgroundWorkerBase, IBackgroundJobWorker public class BackgroundJobWorker : AsyncPeriodicBackgroundWorkerBase, IBackgroundJobWorker
{ {
protected const string DistributedLockName = "AbpBackgroundJobWorker";
protected AbpBackgroundJobOptions JobOptions { get; } protected AbpBackgroundJobOptions JobOptions { get; }
protected AbpBackgroundJobWorkerOptions WorkerOptions { get; } protected AbpBackgroundJobWorkerOptions WorkerOptions { get; }
protected IAbpDistributedLock DistributedLock { get; }
public BackgroundJobWorker( public BackgroundJobWorker(
AbpAsyncTimer timer, AbpAsyncTimer timer,
IOptions<AbpBackgroundJobOptions> jobOptions, IOptions<AbpBackgroundJobOptions> jobOptions,
IOptions<AbpBackgroundJobWorkerOptions> workerOptions, IOptions<AbpBackgroundJobWorkerOptions> workerOptions,
IServiceScopeFactory serviceScopeFactory) IServiceScopeFactory serviceScopeFactory,
IAbpDistributedLock distributedLock)
: base( : base(
timer, timer,
serviceScopeFactory) serviceScopeFactory)
{ {
DistributedLock = distributedLock;
WorkerOptions = workerOptions.Value; WorkerOptions = workerOptions.Value;
JobOptions = jobOptions.Value; JobOptions = jobOptions.Value;
Timer.Period = WorkerOptions.JobPollPeriod; Timer.Period = WorkerOptions.JobPollPeriod;
@ -32,57 +39,74 @@ namespace Volo.Abp.BackgroundJobs
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{ {
var store = workerContext.ServiceProvider.GetRequiredService<IBackgroundJobStore>(); await using (var handler = await DistributedLock.TryAcquireAsync(DistributedLockName, cancellationToken: StoppingToken))
var waitingJobs = await store.GetWaitingJobsAsync(WorkerOptions.MaxJobFetchCount);
if (!waitingJobs.Any())
{ {
return; if (handler != null)
}
var jobExecuter = workerContext.ServiceProvider.GetRequiredService<IBackgroundJobExecuter>();
var clock = workerContext.ServiceProvider.GetRequiredService<IClock>();
var serializer = workerContext.ServiceProvider.GetRequiredService<IBackgroundJobSerializer>();
foreach (var jobInfo in waitingJobs)
{
jobInfo.TryCount++;
jobInfo.LastTryTime = clock.Now;
try
{ {
var jobConfiguration = JobOptions.GetJob(jobInfo.JobName); var store = workerContext.ServiceProvider.GetRequiredService<IBackgroundJobStore>();
var jobArgs = serializer.Deserialize(jobInfo.JobArgs, jobConfiguration.ArgsType);
var context = new JobExecutionContext(workerContext.ServiceProvider, jobConfiguration.JobType, jobArgs);
try var waitingJobs = await store.GetWaitingJobsAsync(WorkerOptions.MaxJobFetchCount);
{
await jobExecuter.ExecuteAsync(context);
await store.DeleteAsync(jobInfo.Id); if (!waitingJobs.Any())
{
return;
} }
catch (BackgroundJobExecutionException)
var jobExecuter = workerContext.ServiceProvider.GetRequiredService<IBackgroundJobExecuter>();
var clock = workerContext.ServiceProvider.GetRequiredService<IClock>();
var serializer = workerContext.ServiceProvider.GetRequiredService<IBackgroundJobSerializer>();
foreach (var jobInfo in waitingJobs)
{ {
var nextTryTime = CalculateNextTryTime(jobInfo, clock); jobInfo.TryCount++;
jobInfo.LastTryTime = clock.Now;
if (nextTryTime.HasValue) try
{ {
jobInfo.NextTryTime = nextTryTime.Value; var jobConfiguration = JobOptions.GetJob(jobInfo.JobName);
var jobArgs = serializer.Deserialize(jobInfo.JobArgs, jobConfiguration.ArgsType);
var context = new JobExecutionContext(
workerContext.ServiceProvider,
jobConfiguration.JobType,
jobArgs);
try
{
await jobExecuter.ExecuteAsync(context);
await store.DeleteAsync(jobInfo.Id);
}
catch (BackgroundJobExecutionException)
{
var nextTryTime = CalculateNextTryTime(jobInfo, clock);
if (nextTryTime.HasValue)
{
jobInfo.NextTryTime = nextTryTime.Value;
}
else
{
jobInfo.IsAbandoned = true;
}
await TryUpdateAsync(store, jobInfo);
}
} }
else catch (Exception ex)
{ {
Logger.LogException(ex);
jobInfo.IsAbandoned = true; jobInfo.IsAbandoned = true;
await TryUpdateAsync(store, jobInfo);
} }
await TryUpdateAsync(store, jobInfo);
} }
} }
catch (Exception ex) else
{ {
Logger.LogException(ex); try
jobInfo.IsAbandoned = true; {
await TryUpdateAsync(store, jobInfo); await Task.Delay(WorkerOptions.JobPollPeriod * 12, StoppingToken);
}
catch (TaskCanceledException) { }
} }
} }
} }
@ -101,7 +125,8 @@ namespace Volo.Abp.BackgroundJobs
protected virtual DateTime? CalculateNextTryTime(BackgroundJobInfo jobInfo, IClock clock) protected virtual DateTime? CalculateNextTryTime(BackgroundJobInfo jobInfo, IClock clock)
{ {
var nextWaitDuration = WorkerOptions.DefaultFirstWaitDuration * (Math.Pow(WorkerOptions.DefaultWaitFactor, jobInfo.TryCount - 1)); var nextWaitDuration = WorkerOptions.DefaultFirstWaitDuration *
(Math.Pow(WorkerOptions.DefaultWaitFactor, jobInfo.TryCount - 1));
var nextTryDate = jobInfo.LastTryTime?.AddSeconds(nextWaitDuration) ?? var nextTryDate = jobInfo.LastTryTime?.AddSeconds(nextWaitDuration) ??
clock.Now.AddSeconds(nextWaitDuration); clock.Now.AddSeconds(nextWaitDuration);
@ -113,4 +138,4 @@ namespace Volo.Abp.BackgroundJobs
return nextTryDate; return nextTryDate;
} }
} }
} }

11
framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkerBase.cs

@ -21,6 +21,15 @@ namespace Volo.Abp.BackgroundWorkers
protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService<ILoggerFactory>(); protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService<ILoggerFactory>();
protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance); protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance);
protected CancellationTokenSource StoppingTokenSource { get; }
protected CancellationToken StoppingToken { get; }
public BackgroundWorkerBase()
{
StoppingTokenSource = new CancellationTokenSource();
StoppingToken = StoppingTokenSource.Token;
}
public virtual Task StartAsync(CancellationToken cancellationToken = default) public virtual Task StartAsync(CancellationToken cancellationToken = default)
{ {
@ -31,6 +40,8 @@ namespace Volo.Abp.BackgroundWorkers
public virtual Task StopAsync(CancellationToken cancellationToken = default) public virtual Task StopAsync(CancellationToken cancellationToken = default)
{ {
Logger.LogDebug("Stopped background worker: " + ToString()); Logger.LogDebug("Stopped background worker: " + ToString());
StoppingTokenSource.Cancel();
StoppingTokenSource.Dispose();
return Task.CompletedTask; return Task.CompletedTask;
} }

2
framework/src/Volo.Abp.Ddd.Domain/Volo.Abp.Ddd.Domain.csproj

@ -17,7 +17,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Auditing\Volo.Abp.Auditing.csproj" /> <ProjectReference Include="..\Volo.Abp.Auditing\Volo.Abp.Auditing.csproj" />
<ProjectReference Include="..\Volo.Abp.Data\Volo.Abp.Data.csproj" /> <ProjectReference Include="..\Volo.Abp.Data\Volo.Abp.Data.csproj" />
<ProjectReference Include="..\Volo.Abp.EventBus.Boxes\Volo.Abp.EventBus.Boxes.csproj" /> <ProjectReference Include="..\Volo.Abp.EventBus\Volo.Abp.EventBus.csproj" />
<ProjectReference Include="..\Volo.Abp.ExceptionHandling\Volo.Abp.ExceptionHandling.csproj" /> <ProjectReference Include="..\Volo.Abp.ExceptionHandling\Volo.Abp.ExceptionHandling.csproj" />
<ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" /> <ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" /> <ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />

2
framework/src/Volo.Abp.Ddd.Domain/Volo.Abp.Ddd.Domain.csproj.DotSettings

@ -1,2 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary>

3
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/AbpDddDomainModule.cs

@ -3,7 +3,6 @@ using Volo.Abp.Auditing;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus; using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Boxes;
using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -19,7 +18,7 @@ namespace Volo.Abp.Domain
[DependsOn( [DependsOn(
typeof(AbpAuditingModule), typeof(AbpAuditingModule),
typeof(AbpDataModule), typeof(AbpDataModule),
typeof(AbpEventBusBoxesModule), typeof(AbpEventBusModule),
typeof(AbpGuidsModule), typeof(AbpGuidsModule),
typeof(AbpMultiTenancyModule), typeof(AbpMultiTenancyModule),
typeof(AbpThreadingModule), typeof(AbpThreadingModule),

3
framework/src/Volo.Abp.DistributedLocking.Abstractions/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

2
framework/src/Volo.Abp.EventBus.Boxes/FodyWeavers.xsd → framework/src/Volo.Abp.DistributedLocking.Abstractions/FodyWeavers.xsd

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> <!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers"> <xs:element name="Weavers">

8
framework/src/Volo.Abp.EventBus.Boxes/Volo.Abp.EventBus.Boxes.csproj → framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo.Abp.DistributedLocking.Abstractions.csproj

@ -5,8 +5,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.EventBus.Boxes</AssemblyName> <AssemblyName>Volo.Abp.DistributedLocking.Abstractions</AssemblyName>
<PackageId>Volo.Abp.EventBus.Boxes</PackageId> <PackageId>Volo.Abp.DistributedLocking.Abstractions</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
@ -15,9 +15,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.BackgroundWorkers\Volo.Abp.BackgroundWorkers.csproj" /> <ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.DistributedLocking\Volo.Abp.DistributedLocking.csproj" />
<ProjectReference Include="..\Volo.Abp.EventBus\Volo.Abp.EventBus.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

9
framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/AbpDistributedLockingAbstractionsModule.cs

@ -0,0 +1,9 @@
using Volo.Abp.Modularity;
namespace Volo.Abp.DistributedLocking
{
public class AbpDistributedLockingAbstractionsModule : AbpModule
{
}
}

26
framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/IAbpDistributedLock.cs

@ -0,0 +1,26 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace Volo.Abp.DistributedLocking
{
public interface IAbpDistributedLock
{
/// <summary>
/// Tries to acquire a named lock.
/// Returns a disposable object to release the lock.
/// It is suggested to use this method within a using block.
/// Returns null if the lock could not be handled.
/// </summary>
/// <param name="name">The name of the lock</param>
/// <param name="timeout">Timeout value</param>
/// <param name="cancellationToken">Cancellation token</param>
[ItemCanBeNull]
Task<IAbpDistributedLockHandle> TryAcquireAsync(
[NotNull] string name,
TimeSpan timeout = default,
CancellationToken cancellationToken = default
);
}
}

9
framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/IAbpDistributedLockHandle.cs

@ -0,0 +1,9 @@
using System;
namespace Volo.Abp.DistributedLocking
{
public interface IAbpDistributedLockHandle : IAsyncDisposable
{
}
}

30
framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/LocalAbpDistributedLock.cs

@ -0,0 +1,30 @@
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.DistributedLocking
{
public class LocalAbpDistributedLock : IAbpDistributedLock, ISingletonDependency
{
private readonly ConcurrentDictionary<string, SemaphoreSlim> _localSyncObjects = new();
public async Task<IAbpDistributedLockHandle> TryAcquireAsync(
string name,
TimeSpan timeout = default,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(name, nameof(name));
var semaphore = _localSyncObjects.GetOrAdd(name, _ => new SemaphoreSlim(1, 1));
if (!await semaphore.WaitAsync(timeout, cancellationToken))
{
return null;
}
return new LocalAbpDistributedLockHandle(semaphore);
}
}
}

21
framework/src/Volo.Abp.DistributedLocking.Abstractions/Volo/Abp/DistributedLocking/LocalAbpDistributedLockHandle.cs

@ -0,0 +1,21 @@
using System.Threading;
using System.Threading.Tasks;
namespace Volo.Abp.DistributedLocking
{
public class LocalAbpDistributedLockHandle : IAbpDistributedLockHandle
{
private readonly SemaphoreSlim _semaphore;
public LocalAbpDistributedLockHandle(SemaphoreSlim semaphore)
{
_semaphore = semaphore;
}
public ValueTask DisposeAsync()
{
_semaphore.Release();
return default;
}
}
}

2
framework/src/Volo.Abp.DistributedLocking/Volo.Abp.DistributedLocking.csproj

@ -15,7 +15,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" /> <ProjectReference Include="..\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

14
framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/AbpDistributedLockHandleExtensions.cs

@ -0,0 +1,14 @@
using System;
using Medallion.Threading;
namespace Volo.Abp.DistributedLocking
{
public static class AbpDistributedLockHandleExtensions
{
public static IDistributedSynchronizationHandle ToDistributedSynchronizationHandle(
this IAbpDistributedLockHandle handle)
{
return handle.As<MedallionAbpDistributedLockHandle>().Handle;
}
}
}

3
framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/AbpDistributedLockingModule.cs

@ -2,6 +2,9 @@
namespace Volo.Abp.DistributedLocking namespace Volo.Abp.DistributedLocking
{ {
[DependsOn(
typeof(AbpDistributedLockingAbstractionsModule)
)]
public class AbpDistributedLockingModule : AbpModule public class AbpDistributedLockingModule : AbpModule
{ {

35
framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/MedallionAbpDistributedLock.cs

@ -0,0 +1,35 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Medallion.Threading;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.DistributedLocking
{
[Dependency(ReplaceServices = true)]
public class MedallionAbpDistributedLock : IAbpDistributedLock, ITransientDependency
{
protected IDistributedLockProvider DistributedLockProvider { get; }
public MedallionAbpDistributedLock(IDistributedLockProvider distributedLockProvider)
{
DistributedLockProvider = distributedLockProvider;
}
public async Task<IAbpDistributedLockHandle> TryAcquireAsync(
string name,
TimeSpan timeout = default,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(name, nameof(name));
var handle = await DistributedLockProvider.TryAcquireLockAsync(name, timeout, cancellationToken);
if (handle == null)
{
return null;
}
return new MedallionAbpDistributedLockHandle(handle);
}
}
}

20
framework/src/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/MedallionAbpDistributedLockHandle.cs

@ -0,0 +1,20 @@
using System.Threading.Tasks;
using Medallion.Threading;
namespace Volo.Abp.DistributedLocking
{
public class MedallionAbpDistributedLockHandle : IAbpDistributedLockHandle
{
public IDistributedSynchronizationHandle Handle { get; }
public MedallionAbpDistributedLockHandle(IDistributedSynchronizationHandle handle)
{
Handle = handle;
}
public ValueTask DisposeAsync()
{
return Handle.DisposeAsync();
}
}
}

3
framework/src/Volo.Abp.EventBus.Boxes/FodyWeavers.xml

@ -1,3 +0,0 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

20
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/AbpEventBusBoxesModule.cs

@ -1,20 +0,0 @@
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Modularity;
namespace Volo.Abp.EventBus.Boxes
{
[DependsOn(
typeof(AbpEventBusModule),
typeof(AbpBackgroundWorkersModule),
typeof(AbpDistributedLockingModule)
)]
public class AbpEventBusBoxesModule : AbpModule
{
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
context.AddBackgroundWorker<OutboxSenderManager>();
context.AddBackgroundWorker<InboxProcessManager>();
}
}
}

20
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/TaskHelper.cs

@ -1,20 +0,0 @@
using System.Threading;
using System.Threading.Tasks;
namespace Volo.Abp.EventBus.Boxes
{
internal static class TaskDelayHelper
{
public static async Task DelayAsync(int milliseconds, CancellationToken cancellationToken = default)
{
try
{
await Task.Delay(milliseconds, cancellationToken);
}
catch (TaskCanceledException)
{
return;
}
}
}
}

2
framework/src/Volo.Abp.EventBus/Volo.Abp.EventBus.csproj

@ -15,6 +15,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.BackgroundWorkers\Volo.Abp.BackgroundWorkers.csproj" />
<ProjectReference Include="..\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj" />
<ProjectReference Include="..\Volo.Abp.EventBus.Abstractions\Volo.Abp.EventBus.Abstractions.csproj" /> <ProjectReference Include="..\Volo.Abp.EventBus.Abstractions\Volo.Abp.EventBus.Abstractions.csproj" />
<ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" /> <ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" />
<ProjectReference Include="..\Volo.Abp.Json\Volo.Abp.Json.csproj" /> <ProjectReference Include="..\Volo.Abp.Json\Volo.Abp.Json.csproj" />

13
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/AbpEventBusModule.cs

@ -1,7 +1,10 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.DistributedLocking;
using Volo.Abp.EventBus.Abstractions; using Volo.Abp.EventBus.Abstractions;
using Volo.Abp.EventBus.Boxes;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
using Volo.Abp.EventBus.Local; using Volo.Abp.EventBus.Local;
using Volo.Abp.Guids; using Volo.Abp.Guids;
@ -16,7 +19,9 @@ namespace Volo.Abp.EventBus
typeof(AbpEventBusAbstractionsModule), typeof(AbpEventBusAbstractionsModule),
typeof(AbpMultiTenancyModule), typeof(AbpMultiTenancyModule),
typeof(AbpJsonModule), typeof(AbpJsonModule),
typeof(AbpGuidsModule) typeof(AbpGuidsModule),
typeof(AbpBackgroundWorkersModule),
typeof(AbpDistributedLockingAbstractionsModule)
)] )]
public class AbpEventBusModule : AbpModule public class AbpEventBusModule : AbpModule
{ {
@ -24,6 +29,12 @@ namespace Volo.Abp.EventBus
{ {
AddEventHandlers(context.Services); AddEventHandlers(context.Services);
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
context.AddBackgroundWorker<OutboxSenderManager>();
context.AddBackgroundWorker<InboxProcessManager>();
}
private static void AddEventHandlers(IServiceCollection services) private static void AddEventHandlers(IServiceCollection services)
{ {

0
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/AbpDistributedEventBusExtensions.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/AbpDistributedEventBusExtensions.cs

0
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/AbpEventBusBoxesOptions.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/AbpEventBusBoxesOptions.cs

0
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/IInboxProcessor.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IInboxProcessor.cs

0
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/IOutboxSender.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IOutboxSender.cs

0
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/InboxProcessManager.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessManager.cs

20
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/InboxProcessor.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs

@ -1,12 +1,12 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Medallion.Threading;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.DistributedLocking;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Timing; using Volo.Abp.Timing;
@ -19,7 +19,7 @@ namespace Volo.Abp.EventBus.Boxes
protected IServiceProvider ServiceProvider { get; } protected IServiceProvider ServiceProvider { get; }
protected AbpAsyncTimer Timer { get; } protected AbpAsyncTimer Timer { get; }
protected IDistributedEventBus DistributedEventBus { get; } protected IDistributedEventBus DistributedEventBus { get; }
protected IDistributedLockProvider DistributedLockProvider { get; } protected IAbpDistributedLock DistributedLock { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IClock Clock { get; } protected IClock Clock { get; }
protected IEventInbox Inbox { get; private set; } protected IEventInbox Inbox { get; private set; }
@ -28,7 +28,7 @@ namespace Volo.Abp.EventBus.Boxes
protected DateTime? LastCleanTime { get; set; } protected DateTime? LastCleanTime { get; set; }
protected string DistributedLockName => "Inbox_" + InboxConfig.Name; protected string DistributedLockName => "AbpInbox_" + InboxConfig.Name;
public ILogger<InboxProcessor> Logger { get; set; } public ILogger<InboxProcessor> Logger { get; set; }
protected CancellationTokenSource StoppingTokenSource { get; } protected CancellationTokenSource StoppingTokenSource { get; }
protected CancellationToken StoppingToken { get; } protected CancellationToken StoppingToken { get; }
@ -37,7 +37,7 @@ namespace Volo.Abp.EventBus.Boxes
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
AbpAsyncTimer timer, AbpAsyncTimer timer,
IDistributedEventBus distributedEventBus, IDistributedEventBus distributedEventBus,
IDistributedLockProvider distributedLockProvider, IAbpDistributedLock distributedLock,
IUnitOfWorkManager unitOfWorkManager, IUnitOfWorkManager unitOfWorkManager,
IClock clock, IClock clock,
IOptions<AbpEventBusBoxesOptions> eventBusBoxesOptions) IOptions<AbpEventBusBoxesOptions> eventBusBoxesOptions)
@ -45,11 +45,11 @@ namespace Volo.Abp.EventBus.Boxes
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
Timer = timer; Timer = timer;
DistributedEventBus = distributedEventBus; DistributedEventBus = distributedEventBus;
DistributedLockProvider = distributedLockProvider; DistributedLock = distributedLock;
UnitOfWorkManager = unitOfWorkManager; UnitOfWorkManager = unitOfWorkManager;
Clock = clock; Clock = clock;
EventBusBoxesOptions = eventBusBoxesOptions.Value; EventBusBoxesOptions = eventBusBoxesOptions.Value;
Timer.Period = EventBusBoxesOptions.PeriodTimeSpan.Milliseconds; Timer.Period = Convert.ToInt32(EventBusBoxesOptions.PeriodTimeSpan.TotalMilliseconds);
Timer.Elapsed += TimerOnElapsed; Timer.Elapsed += TimerOnElapsed;
Logger = NullLogger<InboxProcessor>.Instance; Logger = NullLogger<InboxProcessor>.Instance;
StoppingTokenSource = new CancellationTokenSource(); StoppingTokenSource = new CancellationTokenSource();
@ -84,7 +84,7 @@ namespace Volo.Abp.EventBus.Boxes
return; return;
} }
await using (var handle = await DistributedLockProvider.TryAcquireLockAsync(DistributedLockName, cancellationToken: StoppingToken)) await using (var handle = await DistributedLock.TryAcquireAsync(DistributedLockName, cancellationToken: StoppingToken))
{ {
if (handle != null) if (handle != null)
{ {
@ -120,7 +120,11 @@ namespace Volo.Abp.EventBus.Boxes
else else
{ {
Logger.LogDebug("Could not obtain the distributed lock: " + DistributedLockName); Logger.LogDebug("Could not obtain the distributed lock: " + DistributedLockName);
await TaskDelayHelper.DelayAsync(EventBusBoxesOptions.DistributedLockWaitDuration.Milliseconds, StoppingToken); try
{
await Task.Delay(EventBusBoxesOptions.DistributedLockWaitDuration, StoppingToken);
}
catch (TaskCanceledException) { }
} }
} }
} }

22
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/OutboxSender.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSender.cs

@ -1,12 +1,12 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Medallion.Threading;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.DistributedLocking;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Threading; using Volo.Abp.Threading;
@ -17,11 +17,11 @@ namespace Volo.Abp.EventBus.Boxes
protected IServiceProvider ServiceProvider { get; } protected IServiceProvider ServiceProvider { get; }
protected AbpAsyncTimer Timer { get; } protected AbpAsyncTimer Timer { get; }
protected IDistributedEventBus DistributedEventBus { get; } protected IDistributedEventBus DistributedEventBus { get; }
protected IDistributedLockProvider DistributedLockProvider { get; } protected IAbpDistributedLock DistributedLock { get; }
protected IEventOutbox Outbox { get; private set; } protected IEventOutbox Outbox { get; private set; }
protected OutboxConfig OutboxConfig { get; private set; } protected OutboxConfig OutboxConfig { get; private set; }
protected AbpEventBusBoxesOptions EventBusBoxesOptions { get; } protected AbpEventBusBoxesOptions EventBusBoxesOptions { get; }
protected string DistributedLockName => "Outbox_" + OutboxConfig.Name; protected string DistributedLockName => "AbpOutbox_" + OutboxConfig.Name;
public ILogger<OutboxSender> Logger { get; set; } public ILogger<OutboxSender> Logger { get; set; }
protected CancellationTokenSource StoppingTokenSource { get; } protected CancellationTokenSource StoppingTokenSource { get; }
@ -31,15 +31,15 @@ namespace Volo.Abp.EventBus.Boxes
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
AbpAsyncTimer timer, AbpAsyncTimer timer,
IDistributedEventBus distributedEventBus, IDistributedEventBus distributedEventBus,
IDistributedLockProvider distributedLockProvider, IAbpDistributedLock distributedLock,
IOptions<AbpEventBusBoxesOptions> eventBusBoxesOptions) IOptions<AbpEventBusBoxesOptions> eventBusBoxesOptions)
{ {
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
Timer = timer;
DistributedEventBus = distributedEventBus; DistributedEventBus = distributedEventBus;
DistributedLockProvider = distributedLockProvider; DistributedLock = distributedLock;
EventBusBoxesOptions = eventBusBoxesOptions.Value; EventBusBoxesOptions = eventBusBoxesOptions.Value;
Timer.Period = EventBusBoxesOptions.PeriodTimeSpan.Milliseconds; Timer = timer;
Timer.Period = Convert.ToInt32(EventBusBoxesOptions.PeriodTimeSpan.TotalMilliseconds);
Timer.Elapsed += TimerOnElapsed; Timer.Elapsed += TimerOnElapsed;
Logger = NullLogger<OutboxSender>.Instance; Logger = NullLogger<OutboxSender>.Instance;
StoppingTokenSource = new CancellationTokenSource(); StoppingTokenSource = new CancellationTokenSource();
@ -69,7 +69,7 @@ namespace Volo.Abp.EventBus.Boxes
protected virtual async Task RunAsync() protected virtual async Task RunAsync()
{ {
await using (var handle = await DistributedLockProvider.TryAcquireLockAsync(DistributedLockName, cancellationToken: StoppingToken)) await using (var handle = await DistributedLock.TryAcquireAsync(DistributedLockName, cancellationToken: StoppingToken))
{ {
if (handle != null) if (handle != null)
{ {
@ -100,7 +100,11 @@ namespace Volo.Abp.EventBus.Boxes
else else
{ {
Logger.LogDebug("Could not obtain the distributed lock: " + DistributedLockName); Logger.LogDebug("Could not obtain the distributed lock: " + DistributedLockName);
await TaskDelayHelper.DelayAsync(EventBusBoxesOptions.DistributedLockWaitDuration.Milliseconds, StoppingToken); try
{
await Task.Delay(EventBusBoxesOptions.DistributedLockWaitDuration, StoppingToken);
}
catch (TaskCanceledException) { }
} }
} }
} }

0
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/OutboxSenderManager.cs → framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxSenderManager.cs

3
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs

@ -16,6 +16,7 @@ using Volo.Abp.Http.Modeling;
using Volo.Abp.Http.ProxyScripting.Generators; using Volo.Abp.Http.ProxyScripting.Generators;
using Volo.Abp.Json; using Volo.Abp.Json;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Reflection;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Tracing; using Volo.Abp.Tracing;
@ -55,7 +56,7 @@ namespace Volo.Abp.Http.Client.ClientProxying
arguments = new ClientProxyRequestTypeValue(); arguments = new ClientProxyRequestTypeValue();
} }
var methodUniqueName = $"{typeof(TService).FullName}.{methodName}.{string.Join("-", arguments.Values.Select(x => x.Key.FullName))}"; var methodUniqueName = $"{typeof(TService).FullName}.{methodName}.{string.Join("-", arguments.Values.Select(x => TypeHelper.GetFullNameHandlingNullableAndGenerics(x.Key)))}";
var action = ClientProxyApiDescriptionFinder.FindAction(methodUniqueName); var action = ClientProxyApiDescriptionFinder.FindAction(methodUniqueName);
if (action == null) if (action == null)
{ {

18
framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo.Abp.DistributedLocking.Abstractions.Tests.csproj

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.test.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" />
</ItemGroup>
</Project>

12
framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo/Abp/DistributedLocking/AbpDistributedLockingAbstractionsTestBase.cs

@ -0,0 +1,12 @@
using Volo.Abp.Testing;
namespace Volo.Abp.DistributedLocking
{
public class AbpDistributedLockingAbstractionsTestBase : AbpIntegratedTest<AbpDistributedLockingAbstractionsTestModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

15
framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo/Abp/DistributedLocking/AbpDistributedLockingAbstractionsTestModule.cs

@ -0,0 +1,15 @@
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace Volo.Abp.DistributedLocking
{
[DependsOn(
typeof(AbpTestBaseModule),
typeof(AbpDistributedLockingAbstractionsModule),
typeof(AbpAutofacModule)
)]
public class AbpDistributedLockingAbstractionsTestModule : AbpModule
{
}
}

73
framework/test/Volo.Abp.DistributedLocking.Abstractions.Tests/Volo/Abp/DistributedLocking/LocalDistributedLock_Tests.cs

@ -0,0 +1,73 @@
using System.Threading.Tasks;
using Shouldly;
using Xunit;
namespace Volo.Abp.DistributedLocking
{
public class LocalDistributedLock_Tests : AbpDistributedLockingAbstractionsTestBase
{
private readonly IAbpDistributedLock _distributedLock;
public LocalDistributedLock_Tests()
{
_distributedLock = GetRequiredService<IAbpDistributedLock>();
}
[Fact]
public void Should_Be_Instance_Of_LocalAbpDistributedLock()
{
_distributedLock.ShouldBeOfType<LocalAbpDistributedLock>();
}
[Fact]
public async Task Should_Lock_With_TryAcquire()
{
await using (var handle = await _distributedLock.TryAcquireAsync("lock1"))
{
handle.ShouldNotBeNull();
}
}
[Fact]
public async Task Should_Not_Acquire_If_Already_Locked()
{
await using (var handle = await _distributedLock.TryAcquireAsync("lock1"))
{
handle.ShouldNotBeNull();
await Task.Run(async () =>
{
await using (var handle2 = await _distributedLock.TryAcquireAsync("lock1"))
{
handle2.ShouldBeNull();
}
});
}
await Task.Run(async () =>
{
await using (var handle = await _distributedLock.TryAcquireAsync("lock1"))
{
handle.ShouldNotBeNull();
}
});
}
[Fact]
public async Task Should_Obtain_Multiple_Locks()
{
await using (var handle = await _distributedLock.TryAcquireAsync("lock1"))
{
handle.ShouldNotBeNull();
await Task.Run(async () =>
{
await using (var handle2 = await _distributedLock.TryAcquireAsync("lock2"))
{
handle2.ShouldNotBeNull();
}
});
}
}
}
}

4
modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp/DemoAppModule.cs

@ -1,6 +1,4 @@
using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Autofac;
using Microsoft.Extensions.Logging;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs.DemoApp.Shared; using Volo.Abp.BackgroundJobs.DemoApp.Shared;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore; using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;

2
nupkg/common.ps1

@ -93,6 +93,7 @@ $projects = (
"framework/src/Volo.Abp.Ddd.Application", "framework/src/Volo.Abp.Ddd.Application",
"framework/src/Volo.Abp.Ddd.Application.Contracts", "framework/src/Volo.Abp.Ddd.Application.Contracts",
"framework/src/Volo.Abp.Ddd.Domain", "framework/src/Volo.Abp.Ddd.Domain",
"framework/src/Volo.Abp.DistributedLocking.Abstractions",
"framework/src/Volo.Abp.DistributedLocking", "framework/src/Volo.Abp.DistributedLocking",
"framework/src/Volo.Abp.Emailing", "framework/src/Volo.Abp.Emailing",
"framework/src/Volo.Abp.EntityFrameworkCore", "framework/src/Volo.Abp.EntityFrameworkCore",
@ -104,7 +105,6 @@ $projects = (
"framework/src/Volo.Abp.EntityFrameworkCore.SqlServer", "framework/src/Volo.Abp.EntityFrameworkCore.SqlServer",
"framework/src/Volo.Abp.EventBus.Abstractions", "framework/src/Volo.Abp.EventBus.Abstractions",
"framework/src/Volo.Abp.EventBus", "framework/src/Volo.Abp.EventBus",
"framework/src/Volo.Abp.EventBus.Boxes",
"framework/src/Volo.Abp.EventBus.RabbitMQ", "framework/src/Volo.Abp.EventBus.RabbitMQ",
"framework/src/Volo.Abp.EventBus.Kafka", "framework/src/Volo.Abp.EventBus.Kafka",
"framework/src/Volo.Abp.EventBus.Rebus", "framework/src/Volo.Abp.EventBus.Rebus",

4
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/global.css

File diff suppressed because one or more lines are too long

4
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/index.html

@ -8,7 +8,7 @@
<base href="/" /> <base href="/" />
<!--ABP:Styles--> <!--ABP:Styles-->
<link href="global.css?_v=637697594257346521" rel="stylesheet"/> <link href="global.css?_v=637698989764475053" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/> <link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles--> <!--/ABP:Styles-->
<link href="MyCompanyName.MyProjectName.Blazor.styles.css" rel="stylesheet"/> <link href="MyCompanyName.MyProjectName.Blazor.styles.css" rel="stylesheet"/>
@ -23,7 +23,7 @@
</div> </div>
<!--ABP:Scripts--> <!--ABP:Scripts-->
<script src="global.js?_v=637697594774520008"></script> <script src="global.js?_v=637698989766989664"></script>
<!--/ABP:Scripts--> <!--/ABP:Scripts-->
</body> </body>

4
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/wwwroot/global.css

File diff suppressed because one or more lines are too long

2
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/wwwroot/global.js

File diff suppressed because one or more lines are too long

4
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Blazor.Host/wwwroot/index.html

@ -8,7 +8,7 @@
<base href="/" /> <base href="/" />
<!--ABP:Styles--> <!--ABP:Styles-->
<link href="global.css?_v=637697603975794401" rel="stylesheet"/> <link href="global.css?_v=637698989789981920" rel="stylesheet"/>
<link href="main.css" rel="stylesheet"/> <link href="main.css" rel="stylesheet"/>
<!--/ABP:Styles--> <!--/ABP:Styles-->
</head> </head>
@ -22,7 +22,7 @@
</div> </div>
<!--ABP:Scripts--> <!--ABP:Scripts-->
<script src="global.js?_v=637697603980013099"></script> <script src="global.js?_v=637698989792675882"></script>
<!--/ABP:Scripts--> <!--/ABP:Scripts-->
</body> </body>

Loading…
Cancel
Save