[backend/configuration] Allow configuring of queue job retention
This commit is contained in:
parent
a253e83176
commit
32d6cb555d
4 changed files with 29 additions and 5 deletions
|
@ -13,6 +13,7 @@ public sealed class Config
|
|||
public required SecuritySection Security { get; init; } = new();
|
||||
public required StorageSection Storage { get; init; } = new();
|
||||
public required PerformanceSection Performance { get; init; } = new();
|
||||
public required QueueSection Queue { get; init; } = new();
|
||||
|
||||
public sealed class InstanceSection
|
||||
{
|
||||
|
@ -282,4 +283,15 @@ public sealed class Config
|
|||
[Range(1, int.MaxValue)] public int PreDeliver { get; init; } = 4;
|
||||
[Range(1, int.MaxValue)] public int BackgroundTask { get; init; } = 4;
|
||||
}
|
||||
|
||||
public sealed class QueueSection
|
||||
{
|
||||
public JobRetentionSection JobRetention { get; init; } = new();
|
||||
}
|
||||
|
||||
public sealed class JobRetentionSection
|
||||
{
|
||||
[Range(0, int.MaxValue)] public int Completed = 10;
|
||||
[Range(0, int.MaxValue)] public int Failed = 10;
|
||||
}
|
||||
}
|
|
@ -113,6 +113,8 @@ public static class ServiceExtensions
|
|||
.ConfigureWithValidation<Config.SecuritySection>(configuration, "Security")
|
||||
.ConfigureWithValidation<Config.PerformanceSection>(configuration, "Performance")
|
||||
.ConfigureWithValidation<Config.QueueConcurrencySection>(configuration, "Performance:QueueConcurrency")
|
||||
.ConfigureWithValidation<Config.QueueSection>(configuration, "Queue")
|
||||
.ConfigureWithValidation<Config.JobRetentionSection>(configuration, "Queue:JobRetention")
|
||||
.ConfigureWithValidation<Config.DatabaseSection>(configuration, "Database")
|
||||
.ConfigureWithValidation<Config.StorageSection>(configuration, "Storage")
|
||||
.ConfigureWithValidation<Config.LocalStorageSection>(configuration, "Storage:Local")
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using Iceshrimp.Backend.Core.Configuration;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Iceshrimp.Backend.Core.Tasks;
|
||||
|
||||
|
@ -11,19 +13,20 @@ public class JobCleanupTask : ICronTask
|
|||
{
|
||||
public async Task Invoke(IServiceProvider provider)
|
||||
{
|
||||
var db = provider.GetRequiredService<DatabaseContext>();
|
||||
var queue = provider.GetRequiredService<QueueService>();
|
||||
var db = provider.GetRequiredService<DatabaseContext>();
|
||||
var queue = provider.GetRequiredService<QueueService>();
|
||||
var retention = provider.GetRequiredService<IOptionsSnapshot<Config.JobRetentionSection>>();
|
||||
|
||||
foreach (var name in queue.QueueNames)
|
||||
{
|
||||
await db.Jobs.Where(p => p.Queue == name && p.Status == Job.JobStatus.Completed)
|
||||
.OrderByDescending(p => p.FinishedAt)
|
||||
.Skip(10)
|
||||
.Skip(retention.Value.Completed)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
await db.Jobs.Where(p => p.Queue == name && p.Status == Job.JobStatus.Failed)
|
||||
.OrderByDescending(p => p.FinishedAt)
|
||||
.Skip(100)
|
||||
.Skip(retention.Value.Failed)
|
||||
.ExecuteDeleteAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,13 @@ Deliver = 20
|
|||
PreDeliver = 4
|
||||
BackgroundTask = 4
|
||||
|
||||
;; How many completed & failed jobs to keep around, per queue.
|
||||
;; Excess is trimmed every 15 minutes, oldest jobs first.
|
||||
;; (-1 = no limit)
|
||||
[Queue:JobRetention]
|
||||
Completed = 10
|
||||
Failed = 100
|
||||
|
||||
[Database]
|
||||
;; Hostname, IP address or path to unix socket directory (specifying port is required even for unix sockets)
|
||||
Host = localhost
|
||||
|
|
Loading…
Add table
Reference in a new issue