From 4e7db6ff9fd1cbeccd63bece0ad5b1850ee58d1d Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 22 Feb 2026 17:05:35 +0800 Subject: [PATCH] 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); })));