Browse Source

Update TickerQ docuuments.

pull/24916/head
maliming 1 month ago
parent
commit
4e7db6ff9f
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 29
      docs/en/framework/infrastructure/background-jobs/tickerq.md
  2. 24
      docs/en/framework/infrastructure/background-workers/tickerq.md

29
docs/en/framework/infrastructure/background-jobs/tickerq.md

@ -38,16 +38,20 @@ public override void ConfigureServices(ServiceConfigurationContext context)
### UseAbpTickerQ ### 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 ```csharp
// (default: TickerQStartMode.Immediate) public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
app.UseAbpTickerQ(startMode: ...); {
var app = context.GetApplicationBuilder();
// (default: TickerQStartMode.Immediate)
(app as IHost)?.UseAbpTickerQ(startMode: ...);
}
``` ```
### AbpBackgroundJobsTickerQOptions ### 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 ```csharp
Configure<AbpBackgroundJobsTickerQOptions>(options => Configure<AbpBackgroundJobsTickerQOptions>(options =>
@ -56,11 +60,10 @@ Configure<AbpBackgroundJobsTickerQOptions>(options =>
{ {
Retries = 3, Retries = 3,
RetryIntervals = new[] {30, 60, 120}, // Retry after 30s, 60s, then 2min RetryIntervals = new[] {30, 60, 120}, // Retry after 30s, 60s, then 2min
Priority = TickerTaskPriority.High Priority = TickerTaskPriority.High,
// Optional batching // Optional: run condition for chained jobs
//BatchParent = Guid.Parse("...."), //RunCondition = RunCondition.OnSuccess
//BatchRunCondition = BatchRunCondition.OnSuccess
}); });
options.AddJobConfiguration<MyBackgroundJob2>(new AbpBackgroundJobsTimeTickerConfiguration() options.AddJobConfiguration<MyBackgroundJob2>(new AbpBackgroundJobsTimeTickerConfiguration()
@ -74,7 +77,7 @@ Configure<AbpBackgroundJobsTickerQOptions>(options =>
### Add your own TickerQ Background Jobs Definitions ### 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<TimeTicker>` or `ICronTickerManager<CronTicker>` 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<TimeTickerEntity>` or `ICronTickerManager<CronTickerEntity>` to manage the jobs.
For example, you can add a `CleanupJobs` job definition in the `OnPreApplicationInitializationAsync` method of your module: 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) => 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 service = new CleanupJobs(); // Or get it from the serviceProvider
var request = await TickerRequestProvider.GetRequestAsync<string>(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); var request = await TickerRequestProvider.GetRequestAsync<string>(tickerFunctionContext, cancellationToken);
var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request); var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request);
await service.CleanupLogsAsync(genericContext, cancellationToken); 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<TimeTicker>`: And then you can add a job by using the `ITimeTickerManager<TimeTickerEntity>`:
```csharp ```csharp
var timeTickerManager = context.ServiceProvider.GetRequiredService<ITimeTickerManager<TimeTicker>>(); var timeTickerManager = context.ServiceProvider.GetRequiredService<ITimeTickerManager<TimeTickerEntity>>();
await timeTickerManager.AddAsync(new TimeTicker await timeTickerManager.AddAsync(new TimeTickerEntity
{ {
Function = nameof(CleanupJobs), Function = nameof(CleanupJobs),
ExecutionTime = DateTime.UtcNow.AddSeconds(5), ExecutionTime = DateTime.UtcNow.AddSeconds(5),

24
docs/en/framework/infrastructure/background-workers/tickerq.md

@ -36,11 +36,15 @@ public override void ConfigureServices(ServiceConfigurationContext context)
### UseAbpTickerQ ### 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 ```csharp
// (default: TickerQStartMode.Immediate) public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
app.UseAbpTickerQ(startMode: ...); {
var app = context.GetApplicationBuilder();
// (default: TickerQStartMode.Immediate)
(app as IHost)?.UseAbpTickerQ(startMode: ...);
}
``` ```
### AbpBackgroundWorkersTickerQOptions ### AbpBackgroundWorkersTickerQOptions
@ -61,7 +65,7 @@ Configure<AbpBackgroundWorkersTickerQOptions>(options =>
### Add your own TickerQ Background Worker Definitions ### 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<TimeTicker>` or `ICronTickerManager<CronTicker>` 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<TimeTickerEntity>` or `ICronTickerManager<CronTickerEntity>` to manage the jobs.
For example, you can add a `CleanupJobs` job definition in the `OnPreApplicationInitializationAsync` method of your module: 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) => 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 service = new CleanupJobs(); // Or get it from the serviceProvider
var request = await TickerRequestProvider.GetRequestAsync<string>(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); var request = await TickerRequestProvider.GetRequestAsync<string>(tickerFunctionContext, cancellationToken);
var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request); var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request);
await service.CleanupLogsAsync(genericContext, cancellationToken); 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<CronTicker>`: And then you can add a job by using the `ICronTickerManager<CronTickerEntity>`:
```csharp ```csharp
var cronTickerManager = context.ServiceProvider.GetRequiredService<ICronTickerManager<CronTicker>>(); var cronTickerManager = context.ServiceProvider.GetRequiredService<ICronTickerManager<CronTickerEntity>>();
await cronTickerManager.AddAsync(new CronTicker await cronTickerManager.AddAsync(new CronTickerEntity
{ {
Function = nameof(CleanupJobs), Function = nameof(CleanupJobs),
Expression = "0 */6 * * *", // Every 6 hours 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<CronTicker>` to add a worker: You can specify a cron expression instead of using `ICronTickerManager<CronTickerEntity>` to add a worker:
```csharp ```csharp
abpTickerQFunctionProvider.Functions.TryAdd(nameof(CleanupJobs), (string.Empty, TickerTaskPriority.Normal, new TickerFunctionDelegate(async (cancellationToken, serviceProvider, tickerFunctionContext) => abpTickerQFunctionProvider.Functions.TryAdd(nameof(CleanupJobs), (string.Empty, TickerTaskPriority.Normal, new TickerFunctionDelegate(async (cancellationToken, serviceProvider, tickerFunctionContext) =>
{ {
var service = new CleanupJobs(); var service = new CleanupJobs();
var request = await TickerRequestProvider.GetRequestAsync<string>(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); var request = await TickerRequestProvider.GetRequestAsync<string>(tickerFunctionContext, cancellationToken);
var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request); var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request);
await service.CleanupLogsAsync(genericContext, cancellationToken); await service.CleanupLogsAsync(genericContext, cancellationToken);
}))); })));

Loading…
Cancel
Save