mirror of
https://github.com/bitwarden/server.git
synced 2025-05-29 23:34:53 -05:00
delete expired grants job
This commit is contained in:
parent
5812915677
commit
bfa6f68541
27
src/Admin/Jobs/DatabaseExpiredGrantsJob.cs
Normal file
27
src/Admin/Jobs/DatabaseExpiredGrantsJob.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,10 @@ namespace Bit.Admin.Jobs
|
|||||||
|
|
||||||
public override async Task StartAsync(CancellationToken cancellationToken)
|
public override async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
var everyFridayAt1145pmTrigger = TriggerBuilder.Create()
|
||||||
|
.StartNow()
|
||||||
|
.WithCronSchedule("0 45 23 ? * FRI")
|
||||||
|
.Build();
|
||||||
var everySaturdayAtMidnightTrigger = TriggerBuilder.Create()
|
var everySaturdayAtMidnightTrigger = TriggerBuilder.Create()
|
||||||
.StartNow()
|
.StartNow()
|
||||||
.WithCronSchedule("0 0 0 ? * SAT")
|
.WithCronSchedule("0 0 0 ? * SAT")
|
||||||
@ -30,6 +34,7 @@ namespace Bit.Admin.Jobs
|
|||||||
|
|
||||||
Jobs = new List<Tuple<Type, ITrigger>>
|
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(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger),
|
||||||
new Tuple<Type, ITrigger>(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger)
|
new Tuple<Type, ITrigger>(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger)
|
||||||
};
|
};
|
||||||
@ -41,6 +46,7 @@ namespace Bit.Admin.Jobs
|
|||||||
{
|
{
|
||||||
services.AddTransient<DatabaseUpdateStatisticsJob>();
|
services.AddTransient<DatabaseUpdateStatisticsJob>();
|
||||||
services.AddTransient<DatabaseRebuildlIndexesJob>();
|
services.AddTransient<DatabaseRebuildlIndexesJob>();
|
||||||
|
services.AddTransient<DatabaseExpiredGrantsJob>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,6 @@ namespace Bit.Core.Repositories
|
|||||||
{
|
{
|
||||||
Task UpdateStatisticsAsync();
|
Task UpdateStatisticsAsync();
|
||||||
Task RebuildIndexesAsync();
|
Task RebuildIndexesAsync();
|
||||||
|
Task DeleteExpiredGrantsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,5 +38,16 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
commandTimeout: 86400);
|
commandTimeout: 86400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeleteExpiredGrantsAsync()
|
||||||
|
{
|
||||||
|
using(var connection = new SqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
await connection.ExecuteAsync(
|
||||||
|
"[dbo].[Grant_DeleteExpired]",
|
||||||
|
commandType: CommandType.StoredProcedure,
|
||||||
|
commandTimeout: 86400);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user