diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs index 2385fbb64..91e40d67b 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs @@ -38,13 +38,10 @@ public class QuartzJobCreator : IQuartzJobCreator, ISingletonDependency // 运行时搜寻本地作业 jobType = typeof(QuartzJobSearchJobAdapter); } - else + else if (!typeof(IJob).IsAssignableFrom(jobType)) { - if (!typeof(IJob).IsAssignableFrom(jobType)) - { - var adapterType = typeof(QuartzJobSimpleAdapter<>); - jobType = adapterType.MakeGenericType(jobType); - } + var adapterType = typeof(QuartzJobSimpleAdapter<>); + jobType = adapterType.MakeGenericType(jobType); } if (jobType == null) diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobAdapter.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobAdapter.cs index be72c3341..5fa086544 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobAdapter.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobAdapter.cs @@ -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 : IJobRunnable protected AbpBackgroundJobOptions Options { get; } protected IBackgroundJobExecuter JobExecuter { get; } - protected IServiceScopeFactory ServiceScopeFactory { get; } public BackgroundJobAdapter( IOptions options, - IBackgroundJobExecuter jobExecuter, - IServiceScopeFactory serviceScopeFactory) + IBackgroundJobExecuter jobExecuter) { JobExecuter = jobExecuter; - ServiceScopeFactory = serviceScopeFactory; Options = options.Value; Logger = NullLogger>.Instance; @@ -30,17 +26,20 @@ public class BackgroundJobAdapter : 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(); - args = jsonSerializer.Deserialize(argsJson); - // args = JsonConvert.DeserializeObject(argsJson); + jobArgs = jsonSerializer.Deserialize(argsJson); } - var jobType = Options.GetJob(typeof(TArgs)).JobType; - var jobContext = new JobExecutionContext(scope.ServiceProvider, jobType, args); + var jobConfiguration = Options.GetJob(); + + var jobContext = new JobExecutionContext( + context.ServiceProvider, + jobConfiguration.JobType, + jobArgs, + context.CancellationToken); await JobExecuter.ExecuteAsync(jobContext); } } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs index b6ddcf4db..2fcaca088 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs @@ -86,7 +86,7 @@ public class BackgroundWorkerAdapter : BackgroundWorkerBase, IBackgroun public async Task ExecuteAsync(JobRunnableContext context) { var worker = (IBackgroundWorker)context.GetService(typeof(TWorker)); - var workerContext = new PeriodicBackgroundWorkerContext(ServiceProvider, context.CancellationToken); + var workerContext = new PeriodicBackgroundWorkerContext(context.ServiceProvider, context.CancellationToken); switch (worker) {