mirror of https://github.com/abpframework/abp.git
7 changed files with 125 additions and 94 deletions
@ -1,23 +1,32 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
|
|||
namespace Volo.Abp.BackgroundJobs.Hangfire |
|||
{ |
|||
public class HangfireJobExecutionAdapter<TArgs> |
|||
{ |
|||
protected BackgroundJobOptions Options { get; } |
|||
protected IServiceScopeFactory ServiceScopeFactory { get; } |
|||
protected IBackgroundJobExecuter JobExecuter { get; } |
|||
|
|||
public HangfireJobExecutionAdapter(IOptions<BackgroundJobOptions> options, IBackgroundJobExecuter jobExecuter) |
|||
public HangfireJobExecutionAdapter( |
|||
IOptions<BackgroundJobOptions> options, |
|||
IBackgroundJobExecuter jobExecuter, |
|||
IServiceScopeFactory serviceScopeFactory) |
|||
{ |
|||
JobExecuter = jobExecuter; |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
Options = options.Value; |
|||
} |
|||
|
|||
public void Execute(TArgs args) |
|||
{ |
|||
var jobType = Options.GetJob(typeof(TArgs)).JobType; |
|||
var context = new JobExecutionContext(jobType, args); |
|||
JobExecuter.Execute(context); |
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
var jobType = Options.GetJob(typeof(TArgs)).JobType; |
|||
var context = new JobExecutionContext(scope.ServiceProvider, jobType, args); |
|||
JobExecuter.Execute(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue