From 23123df1132e21124009ffc34f43cf6b1e242948 Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 22 Feb 2026 16:58:32 +0800 Subject: [PATCH 1/6] Update TickerQ package versions and refactor background job management --- Directory.Packages.props | 8 +++--- .../Volo.Abp.BackgroundJobs.TickerQ.csproj | 2 +- .../TickerQ/AbpBackgroundJobsTickerQModule.cs | 2 +- ...bpBackgroundJobsTimeTickerConfiguration.cs | 5 +--- .../TickerQ/AbpTickerQBackgroundJobManager.cs | 13 ++++----- .../Volo.Abp.BackgroundWorkers.TickerQ.csproj | 2 +- .../AbpBackgroundWorkersTickerQModule.cs | 6 ++-- ...pTickerQPeriodicBackgroundWorkerInvoker.cs | 2 +- .../AbpTickerQApplicationBuilderExtensions.cs | 7 +++-- .../Volo.Abp.TickerQ/Volo.Abp.TickerQ.csproj | 2 +- .../Volo/Abp/TickerQ/AbpTickerQModule.cs | 5 +++- .../CleanupJobs.cs | 2 +- .../DemoAppTickerQModule.cs | 28 ++++++++++--------- 13 files changed, 43 insertions(+), 41 deletions(-) rename framework/src/Volo.Abp.TickerQ/Microsoft/{AspNetCore/Builder => Extensions/Hosting}/AbpTickerQApplicationBuilderExtensions.cs (61%) diff --git a/Directory.Packages.props b/Directory.Packages.props index e89f989794..428a3fa877 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -183,10 +183,10 @@ - - - - + + + + diff --git a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo.Abp.BackgroundJobs.TickerQ.csproj b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo.Abp.BackgroundJobs.TickerQ.csproj index df450f5ff6..41d70914a4 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo.Abp.BackgroundJobs.TickerQ.csproj +++ b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo.Abp.BackgroundJobs.TickerQ.csproj @@ -4,7 +4,7 @@ - netstandard2.1;net8.0;net9.0;net10.0 + net10.0 enable Nullable Volo.Abp.BackgroundJobs.TickerQ diff --git a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTickerQModule.cs b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTickerQModule.cs index b5ed598932..3d93fc68a1 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTickerQModule.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTickerQModule.cs @@ -65,7 +65,7 @@ public class AbpBackgroundJobsTickerQModule : AbpModule using (var scope = serviceProvider.CreateScope()) { var jobExecuter = serviceProvider.GetRequiredService(); - var args = await TickerRequestProvider.GetRequestAsync(serviceProvider, context.Id, context.Type); + var args = await TickerRequestProvider.GetRequestAsync(context, cancellationToken); var jobType = options.GetJob(typeof(TArgs)).JobType; var jobExecutionContext = new JobExecutionContext(scope.ServiceProvider, jobType, args!, cancellationToken: cancellationToken); await jobExecuter.ExecuteAsync(jobExecutionContext); diff --git a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTimeTickerConfiguration.cs b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTimeTickerConfiguration.cs index 65b150ea48..ecceaeb28a 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTimeTickerConfiguration.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpBackgroundJobsTimeTickerConfiguration.cs @@ -1,4 +1,3 @@ -using System; using TickerQ.Utilities.Enums; namespace Volo.Abp.BackgroundJobs.TickerQ; @@ -11,7 +10,5 @@ public class AbpBackgroundJobsTimeTickerConfiguration public TickerTaskPriority? Priority { get; set; } - public Guid? BatchParent { get; set; } - - public BatchRunCondition? BatchRunCondition { get; set; } + public RunCondition? RunCondition { get; set; } } diff --git a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpTickerQBackgroundJobManager.cs b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpTickerQBackgroundJobManager.cs index b1a2dbe36d..638c1845f2 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpTickerQBackgroundJobManager.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.TickerQ/Volo/Abp/BackgroundJobs/TickerQ/AbpTickerQBackgroundJobManager.cs @@ -2,8 +2,8 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using TickerQ.Utilities; +using TickerQ.Utilities.Entities; using TickerQ.Utilities.Interfaces.Managers; -using TickerQ.Utilities.Models.Ticker; using Volo.Abp.DependencyInjection; namespace Volo.Abp.BackgroundJobs.TickerQ; @@ -11,12 +11,12 @@ namespace Volo.Abp.BackgroundJobs.TickerQ; [Dependency(ReplaceServices = true)] public class AbpTickerQBackgroundJobManager : IBackgroundJobManager, ITransientDependency { - protected ITimeTickerManager TimeTickerManager { get; } + protected ITimeTickerManager TimeTickerManager { get; } protected AbpBackgroundJobOptions Options { get; } protected AbpBackgroundJobsTickerQOptions TickerQOptions { get; } public AbpTickerQBackgroundJobManager( - ITimeTickerManager timeTickerManager, + ITimeTickerManager timeTickerManager, IOptions options, IOptions tickerQOptions) { @@ -28,7 +28,7 @@ public class AbpTickerQBackgroundJobManager : IBackgroundJobManager, ITransientD public virtual async Task EnqueueAsync(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) { var job = Options.GetJob(typeof(TArgs)); - var timeTicker = new TimeTicker + var timeTicker = new TimeTickerEntity { Id = Guid.NewGuid(), Function = job.JobName, @@ -41,11 +41,10 @@ public class AbpTickerQBackgroundJobManager : IBackgroundJobManager, ITransientD { timeTicker.Retries = config.Retries ?? timeTicker.Retries; timeTicker.RetryIntervals = config.RetryIntervals ?? timeTicker.RetryIntervals; - timeTicker.BatchParent = config.BatchParent ?? timeTicker.BatchParent; - timeTicker.BatchRunCondition = config.BatchRunCondition ?? timeTicker.BatchRunCondition; + timeTicker.RunCondition = config.RunCondition ?? timeTicker.RunCondition; } var result = await TimeTickerManager.AddAsync(timeTicker); - return !result.IsSucceded ? timeTicker.Id.ToString() : result.Result.Id.ToString(); + return !result.IsSucceeded ? timeTicker.Id.ToString() : result.Result.Id.ToString(); } } diff --git a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo.Abp.BackgroundWorkers.TickerQ.csproj b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo.Abp.BackgroundWorkers.TickerQ.csproj index 2c4ab29c97..b62024131d 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo.Abp.BackgroundWorkers.TickerQ.csproj +++ b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo.Abp.BackgroundWorkers.TickerQ.csproj @@ -4,7 +4,7 @@ - netstandard2.1;net8.0;net9.0;net10.0 + net10.0 enable Nullable Volo.Abp.BackgroundWorkers.TickerQ diff --git a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpBackgroundWorkersTickerQModule.cs b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpBackgroundWorkersTickerQModule.cs index 3fb15a50b8..788eee1759 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpBackgroundWorkersTickerQModule.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpBackgroundWorkersTickerQModule.cs @@ -1,8 +1,8 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using TickerQ.Utilities.Entities; using TickerQ.Utilities.Interfaces.Managers; -using TickerQ.Utilities.Models.Ticker; using Volo.Abp.Modularity; using Volo.Abp.TickerQ; @@ -14,11 +14,11 @@ public class AbpBackgroundWorkersTickerQModule : AbpModule public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context) { var abpTickerQBackgroundWorkersProvider = context.ServiceProvider.GetRequiredService(); - var cronTickerManager = context.ServiceProvider.GetRequiredService>(); + var cronTickerManager = context.ServiceProvider.GetRequiredService>(); var abpBackgroundWorkersTickerQOptions = context.ServiceProvider.GetRequiredService>().Value; foreach (var backgroundWorker in abpTickerQBackgroundWorkersProvider.BackgroundWorkers) { - var cronTicker = new CronTicker + var cronTicker = new CronTickerEntity { Function = backgroundWorker.Value.Function, Expression = backgroundWorker.Value.CronExpression diff --git a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpTickerQPeriodicBackgroundWorkerInvoker.cs b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpTickerQPeriodicBackgroundWorkerInvoker.cs index 17cf7cdc87..f09a271017 100644 --- a/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpTickerQPeriodicBackgroundWorkerInvoker.cs +++ b/framework/src/Volo.Abp.BackgroundWorkers.TickerQ/Volo/Abp/BackgroundWorkers/TickerQ/AbpTickerQPeriodicBackgroundWorkerInvoker.cs @@ -3,7 +3,7 @@ using System.Linq.Expressions; using System.Reflection; using System.Threading; using System.Threading.Tasks; -using TickerQ.Utilities.Models; +using TickerQ.Utilities.Base; namespace Volo.Abp.BackgroundWorkers.TickerQ; diff --git a/framework/src/Volo.Abp.TickerQ/Microsoft/AspNetCore/Builder/AbpTickerQApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.TickerQ/Microsoft/Extensions/Hosting/AbpTickerQApplicationBuilderExtensions.cs similarity index 61% rename from framework/src/Volo.Abp.TickerQ/Microsoft/AspNetCore/Builder/AbpTickerQApplicationBuilderExtensions.cs rename to framework/src/Volo.Abp.TickerQ/Microsoft/Extensions/Hosting/AbpTickerQApplicationBuilderExtensions.cs index 4e81565e99..4d1897b200 100644 --- a/framework/src/Volo.Abp.TickerQ/Microsoft/AspNetCore/Builder/AbpTickerQApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.TickerQ/Microsoft/Extensions/Hosting/AbpTickerQApplicationBuilderExtensions.cs @@ -1,16 +1,17 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using TickerQ.DependencyInjection; using TickerQ.Utilities; using TickerQ.Utilities.Enums; using Volo.Abp.TickerQ; -namespace Microsoft.AspNetCore.Builder; +namespace Microsoft.Extensions.Hosting; public static class AbpTickerQApplicationBuilderExtensions { - public static IApplicationBuilder UseAbpTickerQ(this IApplicationBuilder app, TickerQStartMode qStartMode = TickerQStartMode.Immediate) + public static IHost UseAbpTickerQ(this IHost app, TickerQStartMode qStartMode = TickerQStartMode.Immediate) { - var abpTickerQFunctionProvider = app.ApplicationServices.GetRequiredService(); + var abpTickerQFunctionProvider = app.Services.GetRequiredService(); TickerFunctionProvider.RegisterFunctions(abpTickerQFunctionProvider.Functions); TickerFunctionProvider.RegisterRequestType(abpTickerQFunctionProvider.RequestTypes); diff --git a/framework/src/Volo.Abp.TickerQ/Volo.Abp.TickerQ.csproj b/framework/src/Volo.Abp.TickerQ/Volo.Abp.TickerQ.csproj index 89a037bab7..51649a9a86 100644 --- a/framework/src/Volo.Abp.TickerQ/Volo.Abp.TickerQ.csproj +++ b/framework/src/Volo.Abp.TickerQ/Volo.Abp.TickerQ.csproj @@ -4,7 +4,7 @@ - netstandard2.1;net8.0;net9.0;net10.0 + net10.0 enable Nullable Volo.Abp.TickerQ diff --git a/framework/src/Volo.Abp.TickerQ/Volo/Abp/TickerQ/AbpTickerQModule.cs b/framework/src/Volo.Abp.TickerQ/Volo/Abp/TickerQ/AbpTickerQModule.cs index b6c140e962..82b47294e1 100644 --- a/framework/src/Volo.Abp.TickerQ/Volo/Abp/TickerQ/AbpTickerQModule.cs +++ b/framework/src/Volo.Abp.TickerQ/Volo/Abp/TickerQ/AbpTickerQModule.cs @@ -10,7 +10,10 @@ public class AbpTickerQModule : AbpModule { context.Services.AddTickerQ(options => { - options.SetInstanceIdentifier(context.Services.GetApplicationName()); + options.ConfigureScheduler(scheduler => + { + scheduler.NodeIdentifier = context.Services.GetApplicationName(); + }); }); } } diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/CleanupJobs.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/CleanupJobs.cs index 6eca55e09f..3b9da774ae 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/CleanupJobs.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/CleanupJobs.cs @@ -1,7 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using TickerQ.Utilities.Models; +using TickerQ.Utilities.Base; namespace Volo.Abp.BackgroundJobs.DemoApp.TickerQ; diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs index c9a3b957de..d13e39db97 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using TickerQ.Dashboard.DependencyInjection; using TickerQ.DependencyInjection; using TickerQ.Utilities; using TickerQ.Utilities.Enums; using TickerQ.Utilities.Interfaces.Managers; -using TickerQ.Utilities.Models; -using TickerQ.Utilities.Models.Ticker; +using TickerQ.Utilities.Base; +using TickerQ.Utilities.Entities; using Volo.Abp.AspNetCore; using Volo.Abp.Autofac; using Volo.Abp.BackgroundJobs.DemoApp.Shared; @@ -35,13 +36,14 @@ public class DemoAppTickerQModule : AbpModule { context.Services.AddTickerQ(options => { - options.UpdateMissedJobCheckDelay(TimeSpan.FromSeconds(30)); + options.ConfigureScheduler(scheduler => + { + scheduler.FallbackIntervalChecker = TimeSpan.FromSeconds(30); + }); options.AddDashboard(x => { - x.BasePath = "/tickerq-dashboard"; - - x.UseHostAuthentication = true; + x.SetBasePath("/tickerq-dashboard"); }); }); @@ -78,7 +80,7 @@ public class DemoAppTickerQModule : AbpModule abpTickerQFunctionProvider.Functions.TryAdd(nameof(CleanupJobs), (string.Empty, TickerTaskPriority.Normal, new TickerFunctionDelegate(async (cancellationToken, serviceProvider, tickerFunctionContext) => { var service = new CleanupJobs(); - var request = await TickerRequestProvider.GetRequestAsync(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); + var request = await TickerRequestProvider.GetRequestAsync(tickerFunctionContext, cancellationToken); var genericContext = new TickerFunctionContext(tickerFunctionContext, request); await service.CleanupLogsAsync(genericContext, cancellationToken); }))); @@ -92,10 +94,10 @@ public class DemoAppTickerQModule : AbpModule await backgroundWorkerManager.AddAsync(context.ServiceProvider.GetRequiredService()); var app = context.GetApplicationBuilder(); - app.UseAbpTickerQ(); + (app as IHost)?.UseAbpTickerQ(); - var timeTickerManager = context.ServiceProvider.GetRequiredService>(); - await timeTickerManager.AddAsync(new TimeTicker + var timeTickerManager = context.ServiceProvider.GetRequiredService>(); + await timeTickerManager.AddAsync(new TimeTickerEntity { Function = nameof(CleanupJobs), ExecutionTime = DateTime.UtcNow.AddSeconds(5), @@ -104,8 +106,8 @@ public class DemoAppTickerQModule : AbpModule RetryIntervals = new[] { 30, 60, 120 }, // Retry after 30s, 60s, then 2min }); - var cronTickerManager = context.ServiceProvider.GetRequiredService>(); - await cronTickerManager.AddAsync(new CronTicker + var cronTickerManager = context.ServiceProvider.GetRequiredService>(); + await cronTickerManager.AddAsync(new CronTickerEntity { Function = nameof(CleanupJobs), Expression = "* * * * *", // Every minute @@ -134,7 +136,7 @@ public class DemoAppTickerQModule : AbpModule await Task.Delay(1000); - var timeTickerManager = serviceProvider.GetRequiredService>(); + var timeTickerManager = serviceProvider.GetRequiredService>(); var result = await timeTickerManager.DeleteAsync(Guid.Parse(jobId)); } } From 23ba4108fb87bba81d60cd8a6237e4496f83d969 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Feb 2026 08:59:53 +0000 Subject: [PATCH 2/6] docs: update package version changes [skip ci] --- docs/en/package-version-changes.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/en/package-version-changes.md b/docs/en/package-version-changes.md index d0f7114552..519256e0b5 100644 --- a/docs/en/package-version-changes.md +++ b/docs/en/package-version-changes.md @@ -1,5 +1,14 @@ # Package Version Changes +## 10.2.0-preview + +| Package | Old Version | New Version | PR | +|---------|-------------|-------------|-----| +| TickerQ | 2.5.3 | 10.1.1 | #24916 | +| TickerQ.Dashboard | 2.5.3 | 10.1.1 | #24916 | +| TickerQ.EntityFrameworkCore | 2.5.3 | 10.1.1 | #24916 | +| TickerQ.Utilities | 2.5.3 | 10.1.1 | #24916 | + ## 10.1.0 | Package | Old Version | New Version | PR | From 4e7db6ff9fd1cbeccd63bece0ad5b1850ee58d1d Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 22 Feb 2026 17:05:35 +0800 Subject: [PATCH 3/6] Update TickerQ docuuments. --- .../infrastructure/background-jobs/tickerq.md | 29 ++++++++++--------- .../background-workers/tickerq.md | 24 ++++++++------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/docs/en/framework/infrastructure/background-jobs/tickerq.md b/docs/en/framework/infrastructure/background-jobs/tickerq.md index 013a8fde74..8ac79d7e87 100644 --- a/docs/en/framework/infrastructure/background-jobs/tickerq.md +++ b/docs/en/framework/infrastructure/background-jobs/tickerq.md @@ -38,16 +38,20 @@ public override void ConfigureServices(ServiceConfigurationContext context) ### UseAbpTickerQ -You need to call the `UseAbpTickerQ` extension method instead of `AddTickerQ` in the `OnApplicationInitialization` method of your module: +You need to call the `UseAbpTickerQ` extension method in the `OnApplicationInitialization` method of your module. The method is an extension on `IHost`, so cast the application builder accordingly: ```csharp -// (default: TickerQStartMode.Immediate) -app.UseAbpTickerQ(startMode: ...); +public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context) +{ + var app = context.GetApplicationBuilder(); + // (default: TickerQStartMode.Immediate) + (app as IHost)?.UseAbpTickerQ(startMode: ...); +} ``` ### AbpBackgroundJobsTickerQOptions -You can configure the `TimeTicker` properties for specific jobs. For example, you can change `Priority`, `Retries` and `RetryIntervals` properties as shown below: +You can configure the `TimeTickerEntity` properties for specific jobs. For example, you can change `Priority`, `Retries` and `RetryIntervals` properties as shown below: ```csharp Configure(options => @@ -56,11 +60,10 @@ Configure(options => { Retries = 3, RetryIntervals = new[] {30, 60, 120}, // Retry after 30s, 60s, then 2min - Priority = TickerTaskPriority.High + Priority = TickerTaskPriority.High, - // Optional batching - //BatchParent = Guid.Parse("...."), - //BatchRunCondition = BatchRunCondition.OnSuccess + // Optional: run condition for chained jobs + //RunCondition = RunCondition.OnSuccess }); options.AddJobConfiguration(new AbpBackgroundJobsTimeTickerConfiguration() @@ -74,7 +77,7 @@ Configure(options => ### Add your own TickerQ Background Jobs Definitions -ABP will handle the TickerQ job definitions by `AbpTickerQFunctionProvider` service. You shouldn't use `TickerFunction` to add your own job definitions. You can inject and use the `AbpTickerQFunctionProvider` to add your own definitions and use `ITimeTickerManager` or `ICronTickerManager` to manage the jobs. +ABP will handle the TickerQ job definitions by `AbpTickerQFunctionProvider` service. You shouldn't use `TickerFunction` to add your own job definitions. You can inject and use the `AbpTickerQFunctionProvider` to add your own definitions and use `ITimeTickerManager` or `ICronTickerManager` to manage the jobs. For example, you can add a `CleanupJobs` job definition in the `OnPreApplicationInitializationAsync` method of your module: @@ -96,7 +99,7 @@ public override Task OnPreApplicationInitializationAsync(ApplicationInitializati abpTickerQFunctionProvider.Functions.TryAdd(nameof(CleanupJobs), (string.Empty, TickerTaskPriority.Normal, new TickerFunctionDelegate(async (cancellationToken, serviceProvider, tickerFunctionContext) => { var service = new CleanupJobs(); // Or get it from the serviceProvider - var request = await TickerRequestProvider.GetRequestAsync(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); + var request = await TickerRequestProvider.GetRequestAsync(tickerFunctionContext, cancellationToken); var genericContext = new TickerFunctionContext(tickerFunctionContext, request); await service.CleanupLogsAsync(genericContext, cancellationToken); }))); @@ -105,11 +108,11 @@ public override Task OnPreApplicationInitializationAsync(ApplicationInitializati } ``` -And then you can add a job by using the `ITimeTickerManager`: +And then you can add a job by using the `ITimeTickerManager`: ```csharp -var timeTickerManager = context.ServiceProvider.GetRequiredService>(); -await timeTickerManager.AddAsync(new TimeTicker +var timeTickerManager = context.ServiceProvider.GetRequiredService>(); +await timeTickerManager.AddAsync(new TimeTickerEntity { Function = nameof(CleanupJobs), ExecutionTime = DateTime.UtcNow.AddSeconds(5), diff --git a/docs/en/framework/infrastructure/background-workers/tickerq.md b/docs/en/framework/infrastructure/background-workers/tickerq.md index 840b5137cb..8054e10e79 100644 --- a/docs/en/framework/infrastructure/background-workers/tickerq.md +++ b/docs/en/framework/infrastructure/background-workers/tickerq.md @@ -36,11 +36,15 @@ public override void ConfigureServices(ServiceConfigurationContext context) ### UseAbpTickerQ -You need to call the `UseAbpTickerQ` extension method instead of `AddTickerQ` in the `OnApplicationInitialization` method of your module: +You need to call the `UseAbpTickerQ` extension method in the `OnApplicationInitialization` method of your module. The method is an extension on `IHost`, so cast the application builder accordingly: ```csharp -// (default: TickerQStartMode.Immediate) -app.UseAbpTickerQ(startMode: ...); +public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context) +{ + var app = context.GetApplicationBuilder(); + // (default: TickerQStartMode.Immediate) + (app as IHost)?.UseAbpTickerQ(startMode: ...); +} ``` ### AbpBackgroundWorkersTickerQOptions @@ -61,7 +65,7 @@ Configure(options => ### Add your own TickerQ Background Worker Definitions -ABP will handle the TickerQ job definitions by `AbpTickerQFunctionProvider` service. You shouldn't use `TickerFunction` to add your own job definitions. You can inject and use the `AbpTickerQFunctionProvider` to add your own definitions and use `ITimeTickerManager` or `ICronTickerManager` to manage the jobs. +ABP will handle the TickerQ job definitions by `AbpTickerQFunctionProvider` service. You shouldn't use `TickerFunction` to add your own job definitions. You can inject and use the `AbpTickerQFunctionProvider` to add your own definitions and use `ITimeTickerManager` or `ICronTickerManager` to manage the jobs. For example, you can add a `CleanupJobs` job definition in the `OnPreApplicationInitializationAsync` method of your module: @@ -83,7 +87,7 @@ public override Task OnPreApplicationInitializationAsync(ApplicationInitializati abpTickerQFunctionProvider.Functions.TryAdd(nameof(CleanupJobs), (string.Empty, TickerTaskPriority.Normal, new TickerFunctionDelegate(async (cancellationToken, serviceProvider, tickerFunctionContext) => { var service = new CleanupJobs(); // Or get it from the serviceProvider - var request = await TickerRequestProvider.GetRequestAsync(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); + var request = await TickerRequestProvider.GetRequestAsync(tickerFunctionContext, cancellationToken); var genericContext = new TickerFunctionContext(tickerFunctionContext, request); await service.CleanupLogsAsync(genericContext, cancellationToken); }))); @@ -92,11 +96,11 @@ public override Task OnPreApplicationInitializationAsync(ApplicationInitializati } ``` -And then you can add a job by using the `ICronTickerManager`: +And then you can add a job by using the `ICronTickerManager`: ```csharp -var cronTickerManager = context.ServiceProvider.GetRequiredService>(); -await cronTickerManager.AddAsync(new CronTicker +var cronTickerManager = context.ServiceProvider.GetRequiredService>(); +await cronTickerManager.AddAsync(new CronTickerEntity { Function = nameof(CleanupJobs), Expression = "0 */6 * * *", // Every 6 hours @@ -106,13 +110,13 @@ await cronTickerManager.AddAsync(new CronTicker }); ``` -You can specify a cron expression instead of use `ICronTickerManager` to add a worker: +You can specify a cron expression instead of using `ICronTickerManager` to add a worker: ```csharp abpTickerQFunctionProvider.Functions.TryAdd(nameof(CleanupJobs), (string.Empty, TickerTaskPriority.Normal, new TickerFunctionDelegate(async (cancellationToken, serviceProvider, tickerFunctionContext) => { var service = new CleanupJobs(); - var request = await TickerRequestProvider.GetRequestAsync(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); + var request = await TickerRequestProvider.GetRequestAsync(tickerFunctionContext, cancellationToken); var genericContext = new TickerFunctionContext(tickerFunctionContext, request); await service.CleanupLogsAsync(genericContext, cancellationToken); }))); From a881195b3beb569d28815b3adeecfe6de165972d Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 22 Feb 2026 18:00:39 +0800 Subject: [PATCH 4/6] refactor: streamline TickerQ initialization and enhance service access methods --- .../infrastructure/background-jobs/tickerq.md | 5 +-- .../background-workers/tickerq.md | 5 +-- .../AbpApplicationBuilderExtensions.cs | 24 ++++++++++++ ...licationInitializationContextExtensions.cs | 38 +++++++++++++++++++ .../Abp/AspNetCore/AbpAspNetCoreModule.cs | 5 +++ .../DemoAppTickerQModule.cs | 3 +- 6 files changed, 73 insertions(+), 7 deletions(-) diff --git a/docs/en/framework/infrastructure/background-jobs/tickerq.md b/docs/en/framework/infrastructure/background-jobs/tickerq.md index 8ac79d7e87..d2f6d55f8c 100644 --- a/docs/en/framework/infrastructure/background-jobs/tickerq.md +++ b/docs/en/framework/infrastructure/background-jobs/tickerq.md @@ -38,14 +38,13 @@ public override void ConfigureServices(ServiceConfigurationContext context) ### UseAbpTickerQ -You need to call the `UseAbpTickerQ` extension method in the `OnApplicationInitialization` method of your module. The method is an extension on `IHost`, so cast the application builder accordingly: +You need to call the `UseAbpTickerQ` extension method in the `OnApplicationInitialization` method of your module: ```csharp public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { - var app = context.GetApplicationBuilder(); // (default: TickerQStartMode.Immediate) - (app as IHost)?.UseAbpTickerQ(startMode: ...); + context.GetHost().UseAbpTickerQ(startMode: ...); } ``` diff --git a/docs/en/framework/infrastructure/background-workers/tickerq.md b/docs/en/framework/infrastructure/background-workers/tickerq.md index 8054e10e79..ffe3ca46a6 100644 --- a/docs/en/framework/infrastructure/background-workers/tickerq.md +++ b/docs/en/framework/infrastructure/background-workers/tickerq.md @@ -36,14 +36,13 @@ public override void ConfigureServices(ServiceConfigurationContext context) ### UseAbpTickerQ -You need to call the `UseAbpTickerQ` extension method in the `OnApplicationInitialization` method of your module. The method is an extension on `IHost`, so cast the application builder accordingly: +You need to call the `UseAbpTickerQ` extension method in the `OnApplicationInitialization` method of your module: ```csharp public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { - var app = context.GetApplicationBuilder(); // (default: TickerQStartMode.Immediate) - (app as IHost)?.UseAbpTickerQ(startMode: ...); + context.GetHost().UseAbpTickerQ(startMode: ...); } ``` diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs index 3a283cbe36..aab5b5cc2b 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs @@ -38,6 +38,18 @@ public static class AbpApplicationBuilderExtensions Check.NotNull(app, nameof(app)); app.ApplicationServices.GetRequiredService>().Value = app; + if (app is WebApplication webApplication) + { + app.ApplicationServices.GetRequiredService>().Value = webApplication; + } + if (app is IHost host) + { + app.ApplicationServices.GetRequiredService>().Value = host; + } + if (app is IEndpointRouteBuilder endpointRouteBuilder) + { + app.ApplicationServices.GetRequiredService>().Value = endpointRouteBuilder; + } var application = app.ApplicationServices.GetRequiredService(); var applicationLifetime = app.ApplicationServices.GetRequiredService(); @@ -59,6 +71,18 @@ public static class AbpApplicationBuilderExtensions Check.NotNull(app, nameof(app)); app.ApplicationServices.GetRequiredService>().Value = app; + if (app is WebApplication webApplication) + { + app.ApplicationServices.GetRequiredService>().Value = webApplication; + } + if (app is IHost host) + { + app.ApplicationServices.GetRequiredService>().Value = host; + } + if (app is IEndpointRouteBuilder endpointRouteBuilder) + { + app.ApplicationServices.GetRequiredService>().Value = endpointRouteBuilder; + } var application = app.ApplicationServices.GetRequiredService(); var applicationLifetime = app.ApplicationServices.GetRequiredService(); diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs index 1e361d1587..930b081df0 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/ApplicationInitializationContextExtensions.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Volo.Abp.DependencyInjection; @@ -21,6 +23,42 @@ public static class ApplicationInitializationContextExtensions return context.ServiceProvider.GetRequiredService>().Value; } + public static IHost GetHost(this ApplicationInitializationContext context) + { + var host = context.ServiceProvider.GetRequiredService>().Value; + Check.NotNull(host, nameof(host)); + return host; + } + + public static IHost? GetHostOrNull(this ApplicationInitializationContext context) + { + return context.ServiceProvider.GetRequiredService>().Value; + } + + public static IEndpointRouteBuilder GetEndpointRouteBuilder(this ApplicationInitializationContext context) + { + var endpointRouteBuilder = context.ServiceProvider.GetRequiredService>().Value; + Check.NotNull(endpointRouteBuilder, nameof(endpointRouteBuilder)); + return endpointRouteBuilder; + } + + public static IEndpointRouteBuilder? GetEndpointRouteBuilderOrNull(this ApplicationInitializationContext context) + { + return context.ServiceProvider.GetRequiredService>().Value; + } + + public static WebApplication GetWebApplication(this ApplicationInitializationContext context) + { + var webApplication = context.ServiceProvider.GetRequiredService>().Value; + Check.NotNull(webApplication, nameof(webApplication)); + return webApplication; + } + + public static WebApplication? GetWebApplicationOrNull(this ApplicationInitializationContext context) + { + return context.ServiceProvider.GetRequiredService>().Value; + } + public static IWebHostEnvironment GetEnvironment(this ApplicationInitializationContext context) { return context.ServiceProvider.GetRequiredService(); diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/AbpAspNetCoreModule.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/AbpAspNetCoreModule.cs index 405e49753c..a457d3b1eb 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/AbpAspNetCoreModule.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/AbpAspNetCoreModule.cs @@ -2,7 +2,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.StaticWebAssets; using Microsoft.AspNetCore.RequestLocalization; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.FileProviders; using MyCSharp.HttpUserAgentParser.DependencyInjection; using Volo.Abp.AspNetCore.Auditing; @@ -57,6 +59,9 @@ public class AbpAspNetCoreModule : AbpModule AddAspNetServices(context.Services); context.Services.AddObjectAccessor(); + context.Services.AddObjectAccessor(); + context.Services.AddObjectAccessor(); + context.Services.AddObjectAccessor(); context.Services.AddAbpDynamicOptions(); StaticWebAssetsLoader.UseStaticWebAssets(context.Services.GetHostingEnvironment(), context.Services.GetConfiguration()); diff --git a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs index d13e39db97..de3ef3c05d 100644 --- a/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs +++ b/modules/background-jobs/app/Volo.Abp.BackgroundJobs.DemoApp.TickerQ/DemoAppTickerQModule.cs @@ -94,7 +94,8 @@ public class DemoAppTickerQModule : AbpModule await backgroundWorkerManager.AddAsync(context.ServiceProvider.GetRequiredService()); var app = context.GetApplicationBuilder(); - (app as IHost)?.UseAbpTickerQ(); + + context.GetHost().UseAbpTickerQ(); var timeTickerManager = context.ServiceProvider.GetRequiredService>(); await timeTickerManager.AddAsync(new TimeTickerEntity From 344b16afc5787535b644a986b8ab016182b1e362 Mon Sep 17 00:00:00 2001 From: Ma Liming Date: Sun, 22 Feb 2026 18:07:09 +0800 Subject: [PATCH 5/6] Update docs/en/framework/infrastructure/background-jobs/tickerq.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/en/framework/infrastructure/background-jobs/tickerq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/framework/infrastructure/background-jobs/tickerq.md b/docs/en/framework/infrastructure/background-jobs/tickerq.md index d2f6d55f8c..de7b3631f2 100644 --- a/docs/en/framework/infrastructure/background-jobs/tickerq.md +++ b/docs/en/framework/infrastructure/background-jobs/tickerq.md @@ -44,7 +44,7 @@ You need to call the `UseAbpTickerQ` extension method in the `OnApplicationIniti public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { // (default: TickerQStartMode.Immediate) - context.GetHost().UseAbpTickerQ(startMode: ...); + context.GetHost().UseAbpTickerQ(qStartMode: ...); } ``` From 37f87ad1cecb56a0a967e5f2a88778419b6f550d Mon Sep 17 00:00:00 2001 From: Ma Liming Date: Sun, 22 Feb 2026 18:07:18 +0800 Subject: [PATCH 6/6] Update docs/en/framework/infrastructure/background-workers/tickerq.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/en/framework/infrastructure/background-workers/tickerq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/framework/infrastructure/background-workers/tickerq.md b/docs/en/framework/infrastructure/background-workers/tickerq.md index ffe3ca46a6..d4ddde3cd9 100644 --- a/docs/en/framework/infrastructure/background-workers/tickerq.md +++ b/docs/en/framework/infrastructure/background-workers/tickerq.md @@ -42,7 +42,7 @@ You need to call the `UseAbpTickerQ` extension method in the `OnApplicationIniti public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context) { // (default: TickerQStartMode.Immediate) - context.GetHost().UseAbpTickerQ(startMode: ...); + context.GetHost().UseAbpTickerQ(qStartMode: ...); } ```