-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskExecutorService.cs
More file actions
32 lines (25 loc) · 961 Bytes
/
Copy pathTaskExecutorService.cs
File metadata and controls
32 lines (25 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Core.TaskProcessor;
internal class TaskExecutorService : BackgroundService
{
private readonly ITaskProcessor _processor;
private readonly IServiceProvider _serviceProvider;
public TaskExecutorService(ITaskProcessor processor, IServiceProvider serviceProvider)
{
_processor = processor;
_serviceProvider = serviceProvider;
processor.Execute = Execute;
}
private async Task Execute(TaskContext ctx)
{
await using var scope = _serviceProvider.CreateAsyncScope();
if (ctx.Topic == "internal:expression:v1")
await _processor.Executor.InvokeAsync(ctx, scope.ServiceProvider.GetRequiredService)
.ConfigureAwait(false);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _processor.RunAsync(stoppingToken);
}
}