mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
@@ -3,21 +3,14 @@ using SharpbinV3.Server.Data;
|
||||
|
||||
namespace SharpbinV3.Server.Services
|
||||
{
|
||||
public class PasteCleanUpService(
|
||||
IServiceProvider serviceProvider,
|
||||
ILogger<PasteCleanUpService> logger
|
||||
) : BackgroundService
|
||||
public class PasteCleanUpService(IServiceProvider serviceProvider, ILogger<PasteCleanUpService> logger) : BackgroundService
|
||||
{
|
||||
private readonly TimeSpan _period = TimeSpan.FromMinutes(5);
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
using var timer = new PeriodicTimer(_period);
|
||||
await Cleanup(stoppingToken);
|
||||
while (
|
||||
!stoppingToken.IsCancellationRequested
|
||||
&& await timer.WaitForNextTickAsync(stoppingToken)
|
||||
)
|
||||
while (!stoppingToken.IsCancellationRequested && await timer.WaitForNextTickAsync(stoppingToken))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -43,6 +36,7 @@ namespace SharpbinV3.Server.Services
|
||||
await db.SaveChangesAsync(stoppingToken);
|
||||
logger.LogInformation("Deleted {Count} expired pastes", deletedCount);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user