Browse Source
Merge pull request #22759 from abpframework/hangfire-patch
Improve Hangfire Initialization code
pull/22776/head
maliming
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
5 additions and
16 deletions
-
framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpBackgroundJobsHangfireModule.cs
-
framework/src/Volo.Abp.BackgroundWorkers.Hangfire/Volo/Abp/BackgroundWorkers/Hangfire/AbpBackgroundWorkersHangfireModule.cs
|
|
|
@ -25,13 +25,8 @@ public class AbpBackgroundJobsHangfireModule : AbpModule |
|
|
|
if (!options.IsJobExecutionEnabled) |
|
|
|
{ |
|
|
|
var hangfireOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value; |
|
|
|
hangfireOptions.BackgroundJobServerFactory = CreateOnlyEnqueueJobServer; |
|
|
|
context.ServiceProvider.GetRequiredService<JobStorage>(); |
|
|
|
hangfireOptions.BackgroundJobServerFactory = _ => null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private BackgroundJobServer? CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider) |
|
|
|
{ |
|
|
|
serviceProvider.GetRequiredService<JobStorage>(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,5 +1,4 @@ |
|
|
|
using System; |
|
|
|
using Hangfire; |
|
|
|
using Hangfire; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.Hangfire; |
|
|
|
@ -23,17 +22,12 @@ public class AbpBackgroundWorkersHangfireModule : AbpModule |
|
|
|
if (!options.IsEnabled) |
|
|
|
{ |
|
|
|
var hangfireOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpHangfireOptions>>().Value; |
|
|
|
hangfireOptions.BackgroundJobServerFactory = CreateOnlyEnqueueJobServer; |
|
|
|
context.ServiceProvider.GetRequiredService<JobStorage>(); |
|
|
|
hangfireOptions.BackgroundJobServerFactory = _ => null; |
|
|
|
} |
|
|
|
|
|
|
|
context.ServiceProvider |
|
|
|
.GetRequiredService<HangfireBackgroundWorkerManager>() |
|
|
|
.Initialize(); |
|
|
|
} |
|
|
|
|
|
|
|
private BackgroundJobServer? CreateOnlyEnqueueJobServer(IServiceProvider serviceProvider) |
|
|
|
{ |
|
|
|
serviceProvider.GetRequiredService<JobStorage>(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|