Browse Source
Merge pull request #6410 from abpframework/maliming/hangfire-async
Make HangfireJobExecutionAdapter async.
pull/6414/head
liangshiwei
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
14 additions and
25 deletions
-
framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireBackgroundJobManager.cs
-
framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/HangfireJobExecutionAdapter.cs
|
|
|
@ -11,23 +11,14 @@ namespace Volo.Abp.BackgroundJobs.Hangfire |
|
|
|
public virtual Task<string> EnqueueAsync<TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, |
|
|
|
TimeSpan? delay = null) |
|
|
|
{ |
|
|
|
if (!delay.HasValue) |
|
|
|
{ |
|
|
|
return Task.FromResult( |
|
|
|
BackgroundJob.Enqueue<HangfireJobExecutionAdapter<TArgs>>( |
|
|
|
adapter => adapter.Execute(args) |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return Task.FromResult( |
|
|
|
BackgroundJob.Schedule<HangfireJobExecutionAdapter<TArgs>>( |
|
|
|
adapter => adapter.Execute(args), |
|
|
|
delay.Value |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
return Task.FromResult(delay.HasValue |
|
|
|
? BackgroundJob.Schedule<HangfireJobExecutionAdapter<TArgs>>( |
|
|
|
adapter => adapter.ExecuteAsync(args), |
|
|
|
delay.Value |
|
|
|
) |
|
|
|
: BackgroundJob.Enqueue<HangfireJobExecutionAdapter<TArgs>>( |
|
|
|
adapter => adapter.ExecuteAsync(args) |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,8 +1,6 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
|
|
|
|
namespace Volo.Abp.BackgroundJobs.Hangfire |
|
|
|
{ |
|
|
|
@ -22,7 +20,7 @@ namespace Volo.Abp.BackgroundJobs.Hangfire |
|
|
|
Options = options.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public void Execute(TArgs args) |
|
|
|
public async Task ExecuteAsync(TArgs args) |
|
|
|
{ |
|
|
|
if (!Options.IsJobExecutionEnabled) |
|
|
|
{ |
|
|
|
@ -39,8 +37,8 @@ namespace Volo.Abp.BackgroundJobs.Hangfire |
|
|
|
{ |
|
|
|
var jobType = Options.GetJob(typeof(TArgs)).JobType; |
|
|
|
var context = new JobExecutionContext(scope.ServiceProvider, jobType, args); |
|
|
|
AsyncHelper.RunSync(() => JobExecuter.ExecuteAsync(context)); |
|
|
|
await JobExecuter.ExecuteAsync(context); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|