This commit is contained in:
hang
2024-10-21 21:03:22 +08:00
parent 0ac17ac27f
commit 3ff092fbda
2 changed files with 94 additions and 2 deletions
@@ -0,0 +1,30 @@
using IRaCIS.Core.Application.MassTransit.Consumer;
using MassTransit;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
namespace IRaCIS.Core.API.HostService
{
public class RecurringJobConfigurationService :
BackgroundService
{
readonly IServiceScopeFactory _scopeFactory;
public RecurringJobConfigurationService(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await using var scope = _scopeFactory.CreateAsyncScope();
var endpoint = scope.ServiceProvider.GetRequiredService<IPublishEndpoint>();
await endpoint.AddOrUpdateRecurringJob(nameof(MasstransitTestConsumer), new MasstransiTestCommand(), x => x.Every(minutes: 1),
stoppingToken);
}
}
}