1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-26 22:31:30 +01:00

delete expired grants job

This commit is contained in:
Kyle Spearrin 2018-10-09 10:23:52 -04:00
parent 5812915677
commit bfa6f68541
4 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
using Bit.Core.Jobs;
using Bit.Core.Repositories;
using Microsoft.Extensions.Logging;
using Quartz;
namespace Bit.Admin.Jobs
{
public class DatabaseExpiredGrantsJob : BaseJob
{
private readonly IMaintenanceRepository _maintenanceRepository;
public DatabaseExpiredGrantsJob(
IMaintenanceRepository maintenanceRepository,
ILogger<DatabaseExpiredGrantsJob> logger)
: base(logger)
{
_maintenanceRepository = maintenanceRepository;
}
protected async override Task ExecuteJobAsync(IJobExecutionContext context)
{
await _maintenanceRepository.DeleteExpiredGrantsAsync();
}
}
}

View File

@ -19,6 +19,10 @@ namespace Bit.Admin.Jobs
public override async Task StartAsync(CancellationToken cancellationToken)
{
var everyFridayAt1145pmTrigger = TriggerBuilder.Create()
.StartNow()
.WithCronSchedule("0 45 23 ? * FRI")
.Build();
var everySaturdayAtMidnightTrigger = TriggerBuilder.Create()
.StartNow()
.WithCronSchedule("0 0 0 ? * SAT")
@ -30,6 +34,7 @@ namespace Bit.Admin.Jobs
Jobs = new List<Tuple<Type, ITrigger>>
{
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredGrantsJob), everyFridayAt1145pmTrigger),
new Tuple<Type, ITrigger>(typeof(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger),
new Tuple<Type, ITrigger>(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger)
};
@ -41,6 +46,7 @@ namespace Bit.Admin.Jobs
{
services.AddTransient<DatabaseUpdateStatisticsJob>();
services.AddTransient<DatabaseRebuildlIndexesJob>();
services.AddTransient<DatabaseExpiredGrantsJob>();
}
}
}

View File

@ -6,5 +6,6 @@ namespace Bit.Core.Repositories
{
Task UpdateStatisticsAsync();
Task RebuildIndexesAsync();
Task DeleteExpiredGrantsAsync();
}
}

View File

@ -38,5 +38,16 @@ namespace Bit.Core.Repositories.SqlServer
commandTimeout: 86400);
}
}
public async Task DeleteExpiredGrantsAsync()
{
using(var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[Grant_DeleteExpired]",
commandType: CommandType.StoredProcedure,
commandTimeout: 86400);
}
}
}
}