-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add TickerQ Background Worker Integration #23802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
26
commits into
dev
Choose a base branch
from
copilot/fix-d5496b38-0efc-4016-8ab2-970b67675314
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,210
−8
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ff29dd0
Initial plan
Copilot bdcc697
Add TickerQ background worker integration
Copilot 071ef3b
Complete TickerQ integration with tests, samples, and documentation
Copilot e21a776
Add net10.0 target framework to TickerQ projects
Copilot e01916d
Merge branch 'dev' into copilot/fix-d5496b38-0efc-4016-8ab2-970b67675314
maliming 4177061
feat: Introduce TickerQ background job integration
maliming 94ac0d4
Merge branch 'dev' into copilot/fix-d5496b38-0efc-4016-8ab2-970b67675314
maliming 3a9f035
feat: Implement TickerQ background worker management.
maliming ff2c239
Remove TickerQ background worker test project
maliming 4a9f302
feat: Add TickerQ background job support and related modules
maliming b0a1a6b
feat: Add TickerQ integration to documentation and demo module
maliming 5e23008
Add configurable retry options for TickerQ background jobs
maliming eff20f2
Add MyBackgroundWorker demo.
maliming fab7139
Add free disk space step to CI workflow
maliming 2ada873
Move free-disk-space step before checkout in CI
maliming 2750b3a
Add TickerQ dashboard integration to demo app
maliming 185829f
Add priority support to TickerQ job configuration
maliming 9c69d34
Add TickerQ job configuration and dashboard docs
maliming 14c54c4
Refactor TickerQ managers and add worker configuration support
maliming 91f7774
Rename jobType to workerType in options class
maliming ca4bd0e
Remove ExposeServices attribute from worker manager
maliming 7149673
Optimize TickerQ background job and worker invocation
maliming c1b6557
Handling conflicts.
maliming 6aa0528
Update docs-nav.json
EngincanV 76300f4
Fix path separator in solution file and improve docs
EngincanV e8359d1
Remove manual installation steps from TickerQ docs
maliming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
docs/en/framework/infrastructure/background-jobs/tickerq.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# TickerQ Background Job Manager | ||
|
||
[TickerQ](https://tickerq.net/) is a fast, reflection-free background task scheduler for .NET — built with source generators, EF Core integration, cron + time-based execution, and a real-time dashboard. You can integrate TickerQ with the ABP to use it instead of the [default background job manager](../background-jobs). In this way, you can use the same background job API for TickerQ and your code will be independent of TickerQ. If you like, you can directly use TickerQ's API, too. | ||
|
||
> See the [background jobs document](../background-jobs) to learn how to use the background job system. This document only shows how to install and configure the TickerQ integration. | ||
## Installation | ||
|
||
It is suggested to use the [ABP CLI](../../../cli) to install this package. | ||
|
||
### Using the ABP CLI | ||
|
||
Open a command line window in the folder of the project (.csproj file) and type the following command: | ||
|
||
````bash | ||
abp add-package Volo.Abp.BackgroundJobs.TickerQ | ||
```` | ||
|
||
> If you haven't done it yet, you first need to install the [ABP CLI](../../../cli). For other installation options, see [the package description page](https://abp.io/package-detail/Volo.Abp.BackgroundJobs.TickerQ). | ||
## Configuration | ||
|
||
### AddTickerQ | ||
|
||
You can call the `AddTickerQ` extension method in the `ConfigureServices` method of your module to configure TickerQ services: | ||
|
||
> This is optional. ABP will automatically register TickerQ services. | ||
```csharp | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
context.Services.AddTickerQ(x => | ||
{ | ||
// Configure TickerQ options here | ||
}); | ||
} | ||
``` | ||
|
||
### UseAbpTickerQ | ||
|
||
You need to call the `UseAbpTickerQ` extension method instead of `AddTickerQ` in the `OnApplicationInitialization` method of your module: | ||
|
||
```csharp | ||
// (default: TickerQStartMode.Immediate) | ||
app.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: | ||
|
||
```csharp | ||
Configure<AbpBackgroundJobsTickerQOptions>(options => | ||
{ | ||
options.AddJobConfiguration<MyBackgroundJob>(new AbpBackgroundJobsTimeTickerConfiguration() | ||
{ | ||
Retries = 3, | ||
RetryIntervals = new[] {30, 60, 120}, // Retry after 30s, 60s, then 2min | ||
Priority = TickerTaskPriority.High | ||
|
||
// Optional batching | ||
//BatchParent = Guid.Parse("...."), | ||
//BatchRunCondition = BatchRunCondition.OnSuccess | ||
}); | ||
|
||
options.AddJobConfiguration<MyBackgroundJob2>(new AbpBackgroundJobsTimeTickerConfiguration() | ||
{ | ||
Retries = 5, | ||
RetryIntervals = new[] {30, 60, 120}, // Retry after 30s, 60s, then 2min | ||
Priority = TickerTaskPriority.Normal | ||
}); | ||
}); | ||
``` | ||
|
||
### 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. | ||
|
||
For example, you can add a `CleanupJobs` job definition in the `OnPreApplicationInitializationAsync` method of your module: | ||
|
||
```csharp | ||
public class CleanupJobs | ||
{ | ||
public async Task CleanupLogsAsync(TickerFunctionContext<string> tickerContext, CancellationToken cancellationToken) | ||
{ | ||
var logFileName = tickerContext.Request; | ||
Console.WriteLine($"Cleaning up log file: {logFileName} at {DateTime.Now}"); | ||
} | ||
} | ||
``` | ||
|
||
```csharp | ||
public override Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context) | ||
{ | ||
var abpTickerQFunctionProvider = context.ServiceProvider.GetRequiredService<AbpTickerQFunctionProvider>(); | ||
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<string>(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); | ||
var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request); | ||
await service.CleanupLogsAsync(genericContext, cancellationToken); | ||
}))); | ||
abpTickerQFunctionProvider.RequestTypes.TryAdd(nameof(CleanupJobs), (typeof(string).FullName, typeof(string))); | ||
return Task.CompletedTask; | ||
} | ||
``` | ||
|
||
And then you can add a job by using the `ITimeTickerManager<TimeTicker>`: | ||
|
||
```csharp | ||
var timeTickerManager = context.ServiceProvider.GetRequiredService<ITimeTickerManager<TimeTicker>>(); | ||
await timeTickerManager.AddAsync(new TimeTicker | ||
{ | ||
Function = nameof(CleanupJobs), | ||
ExecutionTime = DateTime.UtcNow.AddSeconds(5), | ||
Request = TickerHelper.CreateTickerRequest<string>("cleanup_example_file.txt"), | ||
Retries = 3, | ||
RetryIntervals = new[] { 30, 60, 120 }, // Retry after 30s, 60s, then 2min | ||
}); | ||
``` | ||
|
||
### TickerQ Dashboard and EF Core Integration | ||
|
||
You can install the [TickerQ dashboard](https://tickerq.net/setup/dashboard.html) and [Entity Framework Core](https://tickerq.net/setup/tickerq-ef-core.html) integration by its documentation. There is no specific configuration needed for the ABP integration. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
docs/en/framework/infrastructure/background-workers/tickerq.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# TickerQ Background Worker Manager | ||
|
||
[TickerQ](https://tickerq.net/) is a fast, reflection-free background task scheduler for .NET — built with source generators, EF Core integration, cron + time-based execution, and a real-time dashboard. You can integrate TickerQ with the ABP to use it instead of the [default background worker manager](../background-workers). | ||
|
||
## Installation | ||
|
||
It is suggested to use the [ABP CLI](../../../cli) to install this package. | ||
|
||
### Using the ABP CLI | ||
|
||
Open a command line window in the folder of the project (.csproj file) and type the following command: | ||
|
||
````bash | ||
abp add-package Volo.Abp.BackgroundWorkers.TickerQ | ||
```` | ||
|
||
> If you haven't done it yet, you first need to install the [ABP CLI](../../../cli). For other installation options, see [the package description page](https://abp.io/package-detail/Volo.Abp.BackgroundWorkers.TickerQ). | ||
## Configuration | ||
|
||
### AddTickerQ | ||
|
||
You can call the `AddTickerQ` extension method in the `ConfigureServices` method of your module to configure TickerQ services: | ||
|
||
> This is optional. ABP will automatically register TickerQ services. | ||
```csharp | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
context.Services.AddTickerQ(x => | ||
{ | ||
// Configure TickerQ options here | ||
}); | ||
} | ||
``` | ||
|
||
### UseAbpTickerQ | ||
|
||
You need to call the `UseAbpTickerQ` extension method instead of `AddTickerQ` in the `OnApplicationInitialization` method of your module: | ||
|
||
```csharp | ||
// (default: TickerQStartMode.Immediate) | ||
app.UseAbpTickerQ(startMode: ...); | ||
``` | ||
|
||
### AbpBackgroundWorkersTickerQOptions | ||
|
||
You can configure the `CronTicker` properties for specific jobs. For example, Change `Priority`, `Retries` and `RetryIntervals` properties: | ||
|
||
```csharp | ||
Configure<AbpBackgroundWorkersTickerQOptions>(options => | ||
{ | ||
options.AddConfiguration<MyBackgroundWorker>(new AbpBackgroundWorkersCronTickerConfiguration() | ||
{ | ||
Retries = 3, | ||
RetryIntervals = new[] {30, 60, 120}, // Retry after 30s, 60s, then 2min, | ||
Priority = TickerTaskPriority.High | ||
}); | ||
}); | ||
``` | ||
|
||
### 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. | ||
|
||
For example, you can add a `CleanupJobs` job definition in the `OnPreApplicationInitializationAsync` method of your module: | ||
|
||
```csharp | ||
public class CleanupJobs | ||
{ | ||
public async Task CleanupLogsAsync(TickerFunctionContext<string> tickerContext, CancellationToken cancellationToken) | ||
{ | ||
var logFileName = tickerContext.Request; | ||
Console.WriteLine($"Cleaning up log file: {logFileName} at {DateTime.Now}"); | ||
} | ||
} | ||
``` | ||
|
||
```csharp | ||
public override Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context) | ||
{ | ||
var abpTickerQFunctionProvider = context.ServiceProvider.GetRequiredService<AbpTickerQFunctionProvider>(); | ||
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<string>(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); | ||
var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request); | ||
await service.CleanupLogsAsync(genericContext, cancellationToken); | ||
}))); | ||
abpTickerQFunctionProvider.RequestTypes.TryAdd(nameof(CleanupJobs), (typeof(string).FullName, typeof(string))); | ||
return Task.CompletedTask; | ||
} | ||
``` | ||
|
||
And then you can add a job by using the `ICronTickerManager<CronTicker>`: | ||
|
||
```csharp | ||
var cronTickerManager = context.ServiceProvider.GetRequiredService<ICronTickerManager<CronTicker>>(); | ||
await cronTickerManager.AddAsync(new CronTicker | ||
{ | ||
Function = nameof(CleanupJobs), | ||
Expression = "0 */6 * * *", // Every 6 hours | ||
Request = TickerHelper.CreateTickerRequest<string>("cleanup_example_file.txt"), | ||
Retries = 2, | ||
RetryIntervals = new[] { 60, 300 } | ||
}); | ||
``` | ||
|
||
You can specify a cron expression instead of use `ICronTickerManager<CronTicker>` 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<string>(serviceProvider, tickerFunctionContext.Id, tickerFunctionContext.Type); | ||
var genericContext = new TickerFunctionContext<string>(tickerFunctionContext, request); | ||
await service.CleanupLogsAsync(genericContext, cancellationToken); | ||
}))); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
framework/src/Volo.Abp.BackgroundJobs.TickerQ/FodyWeavers.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
30 changes: 30 additions & 0 deletions
30
framework/src/Volo.Abp.BackgroundJobs.TickerQ/FodyWeavers.xsd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> | ||
<xs:element name="Weavers"> | ||
<xs:complexType> | ||
<xs:all> | ||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> | ||
<xs:complexType> | ||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:all> | ||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="GenerateXsd" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:schema> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.