-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from EasyAbp/fix-updater
Fix statistic data updater and support local event bus
- Loading branch information
Showing
9 changed files
with
142 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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
7 changes: 7 additions & 0 deletions
7
...Management.Domain/EasyAbp/FileManagement/Files/IRecursiveDirectoryStatisticDataUpdater.cs
This file contains 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,7 @@ | ||
using Volo.Abp.EventBus.Distributed; | ||
|
||
namespace EasyAbp.FileManagement.Files; | ||
|
||
public interface IRecursiveDirectoryStatisticDataUpdater : IDistributedEventHandler<SubFilesChangedEto> | ||
{ | ||
} |
This file contains 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
11 changes: 9 additions & 2 deletions
11
src/EasyAbp.FileManagement.Domain/EasyAbp/FileManagement/Files/SubFilesChangedEto.cs
This file contains 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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
using System; | ||
using Volo.Abp.MultiTenancy; | ||
|
||
namespace EasyAbp.FileManagement.Files; | ||
|
||
public class SubFilesChangedEto | ||
public class SubFilesChangedEto : IMultiTenant | ||
{ | ||
public Guid? TenantId { get; set; } | ||
|
||
public Guid DirectoryId { get; set; } | ||
|
||
public bool UseBackgroundJob { get; set; } | ||
|
||
public SubFilesChangedEto() | ||
{ | ||
} | ||
|
||
public SubFilesChangedEto(Guid directoryId) | ||
public SubFilesChangedEto(Guid? tenantId, Guid directoryId, bool useBackgroundJob) | ||
{ | ||
TenantId = tenantId; | ||
DirectoryId = directoryId; | ||
UseBackgroundJob = useBackgroundJob; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/EasyAbp.FileManagement.Domain/EasyAbp/FileManagement/Files/SubFilesUpdateHandlingJob.cs
This file contains 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,20 @@ | ||
using System.Threading.Tasks; | ||
using Volo.Abp.BackgroundJobs; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace EasyAbp.FileManagement.Files; | ||
|
||
public class SubFilesUpdateHandlingJob : AsyncBackgroundJob<SubFilesUpdateHandlingJobArgs>, ITransientDependency | ||
{ | ||
private readonly IRecursiveDirectoryStatisticDataUpdater _updater; | ||
|
||
public SubFilesUpdateHandlingJob(IRecursiveDirectoryStatisticDataUpdater updater) | ||
{ | ||
_updater = updater; | ||
} | ||
|
||
public override async Task ExecuteAsync(SubFilesUpdateHandlingJobArgs args) | ||
{ | ||
await _updater.HandleEventAsync(args.SubFilesChangedEto); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...syAbp.FileManagement.Domain/EasyAbp/FileManagement/Files/SubFilesUpdateHandlingJobArgs.cs
This file contains 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,22 @@ | ||
using System; | ||
using Volo.Abp.MultiTenancy; | ||
|
||
namespace EasyAbp.FileManagement.Files; | ||
|
||
[Serializable] | ||
public class SubFilesUpdateHandlingJobArgs : IMultiTenant | ||
{ | ||
public Guid? TenantId { get; set; } | ||
|
||
public SubFilesChangedEto SubFilesChangedEto { get; set; } | ||
|
||
public SubFilesUpdateHandlingJobArgs() | ||
{ | ||
} | ||
|
||
public SubFilesUpdateHandlingJobArgs(Guid? tenantId, Guid directoryId) | ||
{ | ||
TenantId = tenantId; | ||
SubFilesChangedEto = new SubFilesChangedEto(tenantId, directoryId, false); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test/EasyAbp.FileManagement.TestBase/RealtimeBackgroundJobManager.cs
This file contains 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,40 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Volo.Abp.BackgroundJobs; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace EasyAbp.FileManagement; | ||
|
||
public class RealtimeBackgroundJobManager : IBackgroundJobManager, ITransientDependency | ||
{ | ||
private readonly AbpBackgroundJobOptions _options; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public RealtimeBackgroundJobManager( | ||
IOptions<AbpBackgroundJobOptions> options, | ||
IServiceProvider serviceProvider) | ||
{ | ||
_options = options.Value; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public async Task<string> EnqueueAsync<TArgs>(TArgs args, | ||
BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) | ||
{ | ||
var job = _serviceProvider.GetService(_options.GetJob<TArgs>().JobType); | ||
|
||
switch (job) | ||
{ | ||
case IAsyncBackgroundJob<TArgs> asyncBackgroundJob: | ||
await asyncBackgroundJob.ExecuteAsync(args); | ||
break; | ||
case IBackgroundJob<TArgs> backgroundJob: | ||
backgroundJob.Execute(args); | ||
break; | ||
} | ||
|
||
return null; | ||
} | ||
} |