42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace xAiService.Services
|
|
{
|
|
public class XAiMcpSessionCleanupService : BackgroundService
|
|
{
|
|
//
|
|
private readonly XAiMcpSessionStore store;
|
|
private readonly ILogger<XAiMcpSessionCleanupService> logger;
|
|
|
|
public XAiMcpSessionCleanupService(
|
|
XAiMcpSessionStore store,
|
|
ILogger<XAiMcpSessionCleanupService> logger
|
|
)
|
|
{
|
|
//
|
|
this.store = store;
|
|
this.logger = logger;
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
//
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
//
|
|
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
|
var removed = store.CleanupExpired();
|
|
if (removed > 0)
|
|
{
|
|
//
|
|
logger
|
|
.LogInformation("MCP Session Cleanup: {Count} expired sessions removed", removed);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |