From 2c6e3b565a37983e99857dd79ecb3c16e3246ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SAL=C4=B0H=20=C3=96ZKARA?= Date: Tue, 10 Mar 2026 13:28:00 +0300 Subject: [PATCH] Move anonymous job executor; normalize TickerQ args Move AnonymousJobExecutorAsyncBackgroundJob into the Abstractions package and remove its dependency on ICancellationTokenProvider. The constructor and handler invocation now use a default CancellationToken and unused usings were cleaned up. In AbpTickerQBackgroundJobManager, add NormalizeArgs and use it before creating the ticker request to ensure the provided args match the expected args type. The normalization performs a JSON round-trip when necessary so CreateTickerRequest receives an instance of the correct type. --- .../AnonymousJobExecutorAsyncBackgroundJob.cs | 10 +++------- .../TickerQ/AbpTickerQBackgroundJobManager.cs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) rename framework/src/{Volo.Abp.BackgroundJobs => Volo.Abp.BackgroundJobs.Abstractions}/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs (67%) diff --git a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs b/framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs similarity index 67% rename from framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs rename to framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs index 6bc0c594c7..51f0515e7e 100644 --- a/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.Abstractions/Volo/Abp/BackgroundJobs/AnonymousJobExecutorAsyncBackgroundJob.cs @@ -1,8 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; -using Volo.Abp.Threading; namespace Volo.Abp.BackgroundJobs; @@ -10,16 +9,13 @@ public class AnonymousJobExecutorAsyncBackgroundJob : AsyncBackgroundJob EnqueueAsync(BackgroundJobConfiguration job, object args, BackgroundJobPriority priority, TimeSpan? delay) { + var normalizedArgs = NormalizeArgs(job.ArgsType, args); + var timeTicker = new TimeTickerEntity { Id = Guid.NewGuid(), Function = job.JobName, ExecutionTime = delay == null ? DateTime.UtcNow : DateTime.UtcNow.Add(delay.Value), - Request = CreateTickerRequest(job.ArgsType, args), + Request = CreateTickerRequest(job.ArgsType, normalizedArgs), }; var config = TickerQOptions.GetConfigurationOrNull(job.JobType); @@ -81,6 +83,17 @@ public class AbpTickerQBackgroundJobManager : IBackgroundJobManager, ITransientD return !result.IsSucceeded ? timeTicker.Id.ToString() : result.Result.Id.ToString(); } + protected virtual object NormalizeArgs(Type argsType, object args) + { + if (argsType.IsInstanceOfType(args)) + { + return args; + } + + var serialized = JsonSerializer.Serialize(args); + return JsonSerializer.Deserialize(argsType, serialized)!; + } + protected virtual byte[]? CreateTickerRequest(Type argsType, object args) { return (byte[]?)CreateTickerRequestMethod