|
|
|
@ -1,5 +1,4 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using System.Threading.Tasks; |
|
|
|
@ -14,15 +13,12 @@ public class BackgroundJobAdapter<TArgs> : IJobRunnable |
|
|
|
|
|
|
|
protected AbpBackgroundJobOptions Options { get; } |
|
|
|
protected IBackgroundJobExecuter JobExecuter { get; } |
|
|
|
protected IServiceScopeFactory ServiceScopeFactory { get; } |
|
|
|
|
|
|
|
public BackgroundJobAdapter( |
|
|
|
IOptions<AbpBackgroundJobOptions> options, |
|
|
|
IBackgroundJobExecuter jobExecuter, |
|
|
|
IServiceScopeFactory serviceScopeFactory) |
|
|
|
IBackgroundJobExecuter jobExecuter) |
|
|
|
{ |
|
|
|
JobExecuter = jobExecuter; |
|
|
|
ServiceScopeFactory = serviceScopeFactory; |
|
|
|
Options = options.Value; |
|
|
|
|
|
|
|
Logger = NullLogger<BackgroundJobAdapter<TArgs>>.Instance; |
|
|
|
@ -30,17 +26,20 @@ public class BackgroundJobAdapter<TArgs> : IJobRunnable |
|
|
|
|
|
|
|
public async virtual Task ExecuteAsync(JobRunnableContext context) |
|
|
|
{ |
|
|
|
using var scope = ServiceScopeFactory.CreateScope(); |
|
|
|
object args = null; |
|
|
|
object jobArgs = null; |
|
|
|
if (context.TryGetString(nameof(TArgs), out var argsJson)) |
|
|
|
{ |
|
|
|
var jsonSerializer = context.GetRequiredService<IJsonSerializer>(); |
|
|
|
args = jsonSerializer.Deserialize<TArgs>(argsJson); |
|
|
|
// args = JsonConvert.DeserializeObject<TArgs>(argsJson);
|
|
|
|
jobArgs = jsonSerializer.Deserialize<TArgs>(argsJson); |
|
|
|
} |
|
|
|
|
|
|
|
var jobType = Options.GetJob(typeof(TArgs)).JobType; |
|
|
|
var jobContext = new JobExecutionContext(scope.ServiceProvider, jobType, args); |
|
|
|
var jobConfiguration = Options.GetJob<TArgs>(); |
|
|
|
|
|
|
|
var jobContext = new JobExecutionContext( |
|
|
|
context.ServiceProvider, |
|
|
|
jobConfiguration.JobType, |
|
|
|
jobArgs, |
|
|
|
context.CancellationToken); |
|
|
|
await JobExecuter.ExecuteAsync(jobContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|