feat: owner review 2 phase 2: scheduled jobs and log settings (#10)
CI / Build and test (push) Successful in 7m0s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 13m28s
CI / PostgreSQL 16 integration (push) Successful in 5m52s
CI / PostgreSQL 17 integration (push) Successful in 4m50s
CI / Docker image (push) Successful in 1m4s
Release / Server image (push) Successful in 1m35s
CI / Build and test (push) Successful in 7m0s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 13m28s
CI / PostgreSQL 16 integration (push) Successful in 5m52s
CI / PostgreSQL 17 integration (push) Successful in 4m50s
CI / Docker image (push) Successful in 1m4s
Release / Server image (push) Successful in 1m35s
- Jobs > Scheduled on the desktop and the admin panel. Every timer that queued work is now a visible system schedule: archive scan, upload clean-up, index backup, job-history and audit clean-ups, desktop housekeeping. New actions: verify, thumbnails, proxies, analysis, maintenance, backup, clean-ups, reports. - The scheduler: migration 0007, in-house recurrence, compare-and-set claim, catch-up, scan at start. - Log settings: levels, retention, size parts, total limit, daily or hourly rotation, audit retention, diagnostics share; the server writes Debug/Trace to its files again; logging never fails a job. Upgrade: CHRONOS_LOG_LEVEL set in an existing container locks both levels; migration 0007 is one-way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #10.
This commit is contained in:
1 parent
1f089888e8
commit
af9eeaab9b
349 files changed
+28341
-1304
No files matched your search
@@ -5,21 +5,27 @@ using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Server.Hosting;
|
||||
using LogRotation = Chronos.Core.Diagnostics.LogRotation;
|
||||
|
||||
namespace Chronos.Server.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// The admin panel's view of the configuration (BRIEF §14.8 Settings). Saving writes <c>/data/server.json</c> (only the
|
||||
/// edited keys; secrets and environment values are never written) and applies what can change while running, the
|
||||
/// parallelism and the priority queue included (owner review 1); ports, TLS, chunk size and job history wait for a restart.
|
||||
/// parallelism and the priority queue included (owner review 1), and the log settings through <see cref="ServerLogging"/>
|
||||
/// (owner review 2, R11); ports, TLS and chunk size wait for a restart. Job history is what the housekeeping system
|
||||
/// schedule is reset to (owner review 2, R10): the schedule's own value applies. The audit retention kept here is what the
|
||||
/// audit clean-up schedule is reset to; the endpoint shows that schedule's age limit in its place and puts a new one there
|
||||
/// (<c>SchedulerHost.AuditRetentionAsync</c>, <c>SchedulerHost.ApplyAuditRetentionAsync</c>).
|
||||
/// </summary>
|
||||
public sealed class ServerSettingsStore(ServerOptions options)
|
||||
public sealed class ServerSettingsStore(ServerOptions options, ServerLogging logging)
|
||||
{
|
||||
/// <summary>The kinds of job the server runs, in the order the admin panel lists their levels (downloads and uploads are a client's).</summary>
|
||||
public static IReadOnlyList<JobKind> Kinds { get; } =
|
||||
[
|
||||
JobKind.Render, JobKind.Import, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse, JobKind.DeepAnalyse, JobKind.Thumbs,
|
||||
JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
|
||||
JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move, JobKind.Backup, JobKind.Cleanup,
|
||||
];
|
||||
|
||||
private readonly Lock _gate = new();
|
||||
@@ -36,6 +42,8 @@ public sealed class ServerSettingsStore(ServerOptions options)
|
||||
/// <summary>Validates and saves; returns the error code and the offending setting, or null on success.</summary>
|
||||
public (string Code, string Setting)? Save(ServerSettingsDto request)
|
||||
{
|
||||
// A panel without the log group keeps the log settings as they are.
|
||||
if (request.Logs is null) request = request with { Logs = Current().Logs };
|
||||
if (Validate(request) is { } invalid) return ("invalid_setting", invalid);
|
||||
lock (_gate)
|
||||
{
|
||||
@@ -57,18 +65,31 @@ public sealed class ServerSettingsStore(ServerOptions options)
|
||||
options.MaxUploadBytes = request.MaxUploadBytes;
|
||||
options.TokenLifetimeDays = request.TokenLifetimeDays;
|
||||
options.UploadRetentionHours = request.UploadRetentionHours;
|
||||
options.JobHistoryDays = request.JobHistoryDays;
|
||||
options.Parallelism = request.Parallelism;
|
||||
options.PriorityQueue = request.PriorityQueue;
|
||||
options.JobPriorities = JobPriorityQueue.Changed(Levels(request.JobPriorities));
|
||||
var logs = request.Logs;
|
||||
options.LogLevel = Level(logs.FileLevel);
|
||||
options.ConsoleLogLevel = Level(logs.ConsoleLevel);
|
||||
options.LogRetentionDays = logs.RetentionDays;
|
||||
options.LogMaxFileMb = logs.MaxFileMb;
|
||||
options.LogMaxTotalMb = logs.MaxTotalMb;
|
||||
options.LogRotation = Rotation(logs.Rotation);
|
||||
options.AuditRetentionDays = logs.AuditRetentionDays;
|
||||
options.DiagnosticsLogMb = logs.DiagnosticsLogMb;
|
||||
logging.Apply(options);
|
||||
var restart = request.HttpPort != options.HttpPort || request.HttpsPort != options.HttpsPort
|
||||
|| !string.Equals(request.TlsMode, options.TlsMode.ToString(), StringComparison.OrdinalIgnoreCase)
|
||||
|| request.TlsCert != options.TlsCert || request.TlsKey != options.TlsKey
|
||||
|| request.ChunkSizeBytes != options.ChunkSizeBytes || request.JobHistoryDays != options.JobHistoryDays;
|
||||
|| request.ChunkSizeBytes != options.ChunkSizeBytes;
|
||||
_saved = request with
|
||||
{
|
||||
ServerName = request.ServerName.Trim(),
|
||||
JobPriorities = Priorities(PriorityQueue(options)),
|
||||
Logs = Logs(options),
|
||||
Locked = [.. options.Locked],
|
||||
LockedBy = LockedBy(options),
|
||||
RestartRequired = restart,
|
||||
ProxyWarning = false,
|
||||
};
|
||||
@@ -79,7 +100,20 @@ public sealed class ServerSettingsStore(ServerOptions options)
|
||||
private static ServerSettingsDto Snapshot(ServerOptions o, bool restartRequired) => new(
|
||||
o.ServerName, o.HttpPort, o.HttpsPort, o.TlsMode.ToString().ToLowerInvariant(), o.TlsCert, o.TlsKey, o.Language, o.Parallelism, o.PriorityQueue,
|
||||
Priorities(PriorityQueue(o)), o.Discovery, o.MaxUploadBytes, o.ChunkSizeBytes, o.JobHistoryDays, o.TokenLifetimeDays, o.UploadRetentionHours,
|
||||
[.. o.Locked], restartRequired, ProxyWarning: false);
|
||||
Logs(o), [.. o.Locked], LockedBy(o), restartRequired, ProxyWarning: false);
|
||||
|
||||
/// <summary>The variable that fixes every locked setting (for one a test locks directly, the variable that would).</summary>
|
||||
private static Dictionary<string, string> LockedBy(ServerOptions o) => o.Locked.Distinct(StringComparer.Ordinal).ToDictionary(s => s,
|
||||
s => o.LockedBy.TryGetValue(s, out var variable) ? variable : ServerOptions.VariableOf(s) ?? s, StringComparer.Ordinal);
|
||||
|
||||
private static LogSettingsDto Logs(ServerOptions o) => new(ServerLogging.Wire(o.LogLevel), ServerLogging.Wire(o.ConsoleLogLevel), o.LogRetentionDays,
|
||||
o.LogMaxFileMb, o.LogMaxTotalMb, ServerLogging.Wire(o.LogRotation), o.AuditRetentionDays, o.DiagnosticsLogMb);
|
||||
|
||||
/// <summary>A level <see cref="Validate"/> has checked.</summary>
|
||||
private static LogLevel Level(string wire) => ServerLogging.TryParseLevel(wire, out var level) ? level : LogLevel.Information;
|
||||
|
||||
/// <summary>A rotation <see cref="Validate"/> has checked.</summary>
|
||||
private static LogRotation Rotation(string wire) => ServerLogging.TryParseRotation(wire, out var rotation) ? rotation : LogRotation.Daily;
|
||||
|
||||
/// <summary>The level of every kind the server runs in <paramref name="queue"/>.</summary>
|
||||
private static List<JobPriorityDto> Priorities(JobPriorityQueue queue) =>
|
||||
@@ -113,7 +147,11 @@ public sealed class ServerSettingsStore(ServerOptions options)
|
||||
if (r.JobHistoryDays is < 1 or > 3650) return nameof(ServerOptions.JobHistoryDays);
|
||||
if (r.TokenLifetimeDays is < 1 or > 365) return nameof(ServerOptions.TokenLifetimeDays);
|
||||
if (r.UploadRetentionHours is < 1 or > 8760) return nameof(ServerOptions.UploadRetentionHours);
|
||||
return null;
|
||||
var logs = r.Logs;
|
||||
if (!ServerLogging.TryParseLevel(logs.FileLevel, out _)) return nameof(ServerOptions.LogLevel);
|
||||
if (!ServerLogging.TryParseLevel(logs.ConsoleLevel, out _)) return nameof(ServerOptions.ConsoleLogLevel);
|
||||
if (!ServerLogging.TryParseRotation(logs.Rotation, out _)) return nameof(ServerOptions.LogRotation);
|
||||
return ServerLogging.Problem(logs.RetentionDays, logs.MaxFileMb, logs.MaxTotalMb, logs.AuditRetentionDays, logs.DiagnosticsLogMb);
|
||||
}
|
||||
|
||||
/// <summary>Settings whose value differs, as server.json keys and JSON values.</summary>
|
||||
@@ -144,6 +182,15 @@ public sealed class ServerSettingsStore(ServerOptions options)
|
||||
Add(nameof(ServerOptions.JobHistoryDays), a.JobHistoryDays, b.JobHistoryDays, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.TokenLifetimeDays), a.TokenLifetimeDays, b.TokenLifetimeDays, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.UploadRetentionHours), a.UploadRetentionHours, b.UploadRetentionHours, v => JsonValue.Create(v));
|
||||
// Levels and the rotation are stored by name, as server.json reads them ("Debug", "Hourly").
|
||||
Add(nameof(ServerOptions.LogLevel), Level(a.Logs.FileLevel), Level(b.Logs.FileLevel), v => JsonValue.Create(v.ToString()));
|
||||
Add(nameof(ServerOptions.ConsoleLogLevel), Level(a.Logs.ConsoleLevel), Level(b.Logs.ConsoleLevel), v => JsonValue.Create(v.ToString()));
|
||||
Add(nameof(ServerOptions.LogRetentionDays), a.Logs.RetentionDays, b.Logs.RetentionDays, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.LogMaxFileMb), a.Logs.MaxFileMb, b.Logs.MaxFileMb, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.LogMaxTotalMb), a.Logs.MaxTotalMb, b.Logs.MaxTotalMb, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.LogRotation), Rotation(a.Logs.Rotation), Rotation(b.Logs.Rotation), v => JsonValue.Create(v.ToString()));
|
||||
Add(nameof(ServerOptions.AuditRetentionDays), a.Logs.AuditRetentionDays, b.Logs.AuditRetentionDays, v => JsonValue.Create(v));
|
||||
Add(nameof(ServerOptions.DiagnosticsLogMb), a.Logs.DiagnosticsLogMb, b.Logs.DiagnosticsLogMb, v => JsonValue.Create(v));
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user