Browse Source
Merge pull request #11142 from abpframework/liangshiwei/workers
Fix the problem of background workers integration
pull/11144/head
maliming
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
23 additions and
7 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
-
framework/src/Volo.Abp.BackgroundWorkers.Quartz/Volo/Abp/BackgroundWorkers/Quartz/QuartzPeriodicBackgroundWorkerAdapter.cs
|
|
|
@ -10,7 +10,7 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire |
|
|
|
[DependsOn( |
|
|
|
typeof(AbpBackgroundWorkersModule), |
|
|
|
typeof(AbpHangfireModule))] |
|
|
|
public class AbpBackgroundWorkerHangfireModule : AbpModule |
|
|
|
public class AbpBackgroundWorkersHangfireModule : AbpModule |
|
|
|
{ |
|
|
|
public override void OnPreApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -42,9 +42,17 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire |
|
|
|
|
|
|
|
if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase) |
|
|
|
{ |
|
|
|
var timer = (AbpAsyncTimer) worker.GetType() |
|
|
|
var timer = worker.GetType() |
|
|
|
.GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); |
|
|
|
period = timer?.Period; |
|
|
|
|
|
|
|
if (worker is AsyncPeriodicBackgroundWorkerBase) |
|
|
|
{ |
|
|
|
period = ((AbpAsyncTimer)timer)?.Period; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
period = ((AbpTimer)timer)?.Period; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -82,7 +90,7 @@ namespace Volo.Abp.BackgroundWorkers.Hangfire |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
cron = $"0 0 */{time.TotalDays} * *"; |
|
|
|
throw new AbpException($"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker"); |
|
|
|
} |
|
|
|
|
|
|
|
return cron; |
|
|
|
|
|
|
|
@ -28,15 +28,23 @@ namespace Volo.Abp.BackgroundWorkers.Quartz |
|
|
|
int? period; |
|
|
|
var workerType = worker.GetType(); |
|
|
|
|
|
|
|
if (worker is AsyncPeriodicBackgroundWorkerBase || worker is PeriodicBackgroundWorkerBase) |
|
|
|
if (worker is AsyncPeriodicBackgroundWorkerBase or PeriodicBackgroundWorkerBase) |
|
|
|
{ |
|
|
|
if (typeof(TWorker) != worker.GetType()) |
|
|
|
{ |
|
|
|
throw new ArgumentException($"{nameof(worker)} type is different from the generic type"); |
|
|
|
} |
|
|
|
|
|
|
|
var timer = (AbpAsyncTimer) worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); |
|
|
|
period = timer?.Period; |
|
|
|
var timer = worker.GetType().GetProperty("Timer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(worker); |
|
|
|
|
|
|
|
if (worker is AsyncPeriodicBackgroundWorkerBase) |
|
|
|
{ |
|
|
|
period = ((AbpAsyncTimer)timer)?.Period; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
period = ((AbpTimer)timer)?.Period; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|