- ABP Framework version: v6.0.0
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
We are using ICancellationTokenProvider for our repositories with the GetCancellationToken() method, so we don't have to sprinkle the CancellationTokens into every method. This works well with the HttpContext Token Provider.
We would like to do the same thing with Background Workers (we are using HangfireBackgroundWorkerBase) - but we are not sure how to... any pointers? Or do we need to convert our Repositories to take CancellationTokens as parameters for this to work properly?
Thanks
7 Answer(s)
-
0
Thanks, but this is not what I'm asking (I think)
Background WORKERS already support CancellationTokens:
public abstract class HangfireBackgroundWorkerBase : BackgroundWorkerBase, IHangfireBackgroundWorker` { public string RecurringJobId { get; set; } public string CronExpression { get; set; } public TimeZoneInfo TimeZone { get; set; } public string Queue { get; set; } public abstract Task DoWorkAsync(CancellationToken cancellationToken = default); protected HangfireBackgroundWorkerBase() { TimeZone = null; Queue = "default"; } }But here, I have to pass the CancellationToken down to my repository methods (which I don't have to do in the normal Http project, as it uses the HttpContextCancellationTokenProvider)
My question is if I can somehow make BackgroundWorkers work the same, without adding CancellationToken overloads to the Repository methods, as my Repository methods use GetCancellationToken() to pass the token from the ICancellationTokenProvider
Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
hi
The AddBackgroundWorkerAsync method has a CancellationToken parameter.
https://github.com/abpframework/abp/blob/6cd1e05fdc0d15888d2e25f1cb0765f1e8db9008/framework/src/Volo.Abp.BackgroundWorkers/Volo/Abp/BackgroundWorkers/BackgroundWorkersApplicationInitializationContextExtensions.cs#L11
https://github.com/abpframework/abp/pull/12420
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi, I don't think this is what I need, altough might be helpful.
Maybe I need to describe it differently what I want. I want on shutdown of the Application that hosts the Background Workers to issue a cancellation token that can somehow be used/injected as ICancellationTokenProvider, as we (currently) exclusively use the ICancellationTokenProvider to cancel work in the Repositories.
How would AddBackgroundWorkerAsync with a CancellationToken parameter work here?
Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
I want on shutdown of the Application that hosts the Background Workers to issue a cancellation token that can somehow be used/injected as ICancellationTokenProvider,
Currently not possible.
How would AddBackgroundWorkerAsync with a CancellationToken parameter work here?
Something like this
https://github.com/abpframework/abp/blob/0c21d295c5989da948fe208c74277d0cbb895aa2/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/AbpEventBusModule.cs#L36
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
I want on shutdown of the Application that hosts the Background Workers to issue a cancellation token that can somehow be used/injected as ICancellationTokenProvider,
Currently not possible.
OK, thank you
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
