@@ -19,27 +19,37 @@ dotnet add package Core.TaskProcessor
19
19
## Initialization in AspNetCore
20
20
21
21
``` csharp
22
- builder .Services .AddTaskProcessor (new TaskProcessorOptions
22
+ builder .Services .AddTaskProcessor (( sp , options ) =>
23
23
{
24
- Redis = " localhost:6379,abortConnect=false" ,
25
- Prefix = " {coretask}" , // redis cluster mode needs single hash slot
26
- Queues = new [] { " high" , " default" , " low" }, // pop queues from left to right - first non empty queue wins
27
- MaxWorkers = 4 , // action block concurrency limit
28
- Retries = 3 ,
29
- Invisibility = TimeSpan .FromMinutes (5 ), // task will be redelivered when taking longer than this
30
- BaseFrequency = TimeSpan .FromSeconds (5 ), // fetches tasks when reactive events failed
31
- PushbackFrequency = TimeSpan .FromSeconds (10 ), // how often to run task retry/delay pushbacks
32
- CleanUpFrequency = TimeSpan .FromMinutes (5 ), // how often to run batch cleanups
33
- Retention = TimeSpan .FromDays (7 ), // batch information will be kept this long
34
- UseHostedService = true , // use supplied background worker service
35
- OnTaskFailedDelay = (ctx , retry ) => // delay retry on task failure
24
+ options .Redis = " localhost:6379,abortConnect=false" ;
25
+ options .Prefix = " {coretask}" ; // redis cluster mode needs single hash slot
26
+ options .Queues = [" high" , " default" , " low" ]; // pop queues from left to right - first non empty queue wins
27
+ options .MaxWorkers = 4 ; // action block concurrency limit
28
+ options .Retries = 3 ; // if tasks fails x times its discarded or deadlettered
29
+ options .Invisibility = TimeSpan .FromMinutes (5 ); // task will be redelivered when taking longer than this
30
+ options .BaseFrequency = TimeSpan .FromSeconds (5 ); // fetches tasks when reactive events failed
31
+ options .PushbackFrequency = TimeSpan .FromSeconds (10 ); // how often to run task retry/delay pushbacks
32
+ options .CleanUpFrequency = TimeSpan .FromMinutes (5 ); // how often to run batch cleanups
33
+ options .Retention = TimeSpan .FromDays (7 ); // batch information will be kept this long
34
+ options .Deadletter = true ; // move failed tasks to deadletter queues
35
+ options .DeadletterUniqueSchedules = false ; // ignore deadletter for unique schedules or they will pause indefinatly
36
+ options .UseCronSeconds = false ;
37
+ options .OnTaskFailedDelay = (_ , retry ) => // delay retry on task failure
36
38
Task .FromResult (retry switch
37
39
{
38
40
2 => TimeSpan .FromSeconds (5 ),
39
41
1 => TimeSpan .FromSeconds (60 ),
40
- _ => (TimeSpan ?)null ,
41
- })
42
+ _ => (TimeSpan ?)null
43
+ });
44
+ options .OnTaskError = (_ , exception ) =>
45
+ {
46
+ sp .GetRequiredService <ILogger <ITaskProcessor >>()
47
+ .LogError (exception , " Task Error" );
48
+
49
+ return Task .CompletedTask ;
50
+ };
42
51
});
52
+ builder .Services .AddTaskProcessorExecutor ();
43
53
```
44
54
45
55
## Enqueue batch tasks
0 commit comments