Browse Source
Merge pull request #18481 from abpframework/auto-merge/rel-7-4/2355
Merge branch rel-8.0 with rel-7.4
pull/18482/head
maliming
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
6 additions and
11 deletions
-
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs
-
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/HangfireBackgroundWorkerManager.cs
|
|
|
@ -19,7 +19,7 @@ public class AbpBackgroundWorkersHangfireModule : AbpModule |
|
|
|
context.Services.AddSingleton(typeof(HangfirePeriodicBackgroundWorkerAdapter<>)); |
|
|
|
} |
|
|
|
|
|
|
|
public async override Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context) |
|
|
|
public override void OnPreApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpBackgroundWorkerOptions>>().Value; |
|
|
|
if (!options.IsEnabled) |
|
|
|
@ -28,14 +28,9 @@ public class AbpBackgroundWorkersHangfireModule : AbpModule |
|
|
|
hangfireOptions.BackgroundJobServerFactory = CreateOnlyEnqueueJobServer; |
|
|
|
} |
|
|
|
|
|
|
|
await context.ServiceProvider |
|
|
|
.GetRequiredService<IBackgroundWorkerManager>() |
|
|
|
.StartAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnPreApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(() => OnPreApplicationInitializationAsync(context)); |
|
|
|
context.ServiceProvider |
|
|
|
.GetRequiredService<HangfireBackgroundWorkerManager>() |
|
|
|
.Initialize(); |
|
|
|
} |
|
|
|
|
|
|
|
private BackgroundJobServer? CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider) |
|
|
|
|
|
|
|
@ -12,6 +12,7 @@ using Volo.Abp.Threading; |
|
|
|
namespace Volo.Abp.BackgroundWorkers.Hangfire; |
|
|
|
|
|
|
|
[Dependency(ReplaceServices = true)] |
|
|
|
[ExposeServices(typeof(IBackgroundWorkerManager), typeof(HangfireBackgroundWorkerManager))] |
|
|
|
public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISingletonDependency |
|
|
|
{ |
|
|
|
protected AbpHangfireBackgroundJobServer BackgroundJobServer { get; set; } = default!; |
|
|
|
@ -22,10 +23,9 @@ public class HangfireBackgroundWorkerManager : BackgroundWorkerManager, ISinglet |
|
|
|
ServiceProvider = serviceProvider; |
|
|
|
} |
|
|
|
|
|
|
|
public async override Task StartAsync(CancellationToken cancellationToken = default) |
|
|
|
public void Initialize() |
|
|
|
{ |
|
|
|
BackgroundJobServer = ServiceProvider.GetRequiredService<AbpHangfireBackgroundJobServer>(); |
|
|
|
await base.StartAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public async override Task AddAsync(IBackgroundWorker worker, CancellationToken cancellationToken = default) |
|
|
|
|