1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-04 12:40:22 -05:00
bitwarden/src/Admin/Jobs/DeleteSendsJob.cs
2021-12-16 15:35:09 +01:00

49 lines
1.5 KiB
C#

using System;
using System.Linq;
using System.Threading.Tasks;
using Bit.Core;
using Bit.Core.Context;
using Bit.Core.Jobs;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Quartz;
namespace Bit.Admin.Jobs
{
public class DeleteSendsJob : BaseJob
{
private readonly ISendRepository _sendRepository;
private readonly IServiceProvider _serviceProvider;
public DeleteSendsJob(
ISendRepository sendRepository,
IServiceProvider serviceProvider,
ILogger<DatabaseExpiredGrantsJob> logger)
: base(logger)
{
_sendRepository = sendRepository;
_serviceProvider = serviceProvider;
}
protected async override Task ExecuteJobAsync(IJobExecutionContext context)
{
var sends = await _sendRepository.GetManyByDeletionDateAsync(DateTime.UtcNow);
_logger.LogInformation(Constants.BypassFiltersEventId, "Deleting {0} sends.", sends.Count);
if (!sends.Any())
{
return;
}
using (var scope = _serviceProvider.CreateScope())
{
var sendService = scope.ServiceProvider.GetRequiredService<ISendService>();
foreach (var send in sends)
{
await sendService.DeleteSendAsync(send);
}
}
}
}
}