feat(server): scheduled jobs on the server and a Scheduled tab in the admin panel
Owner review 2, R10: nothing may run out of sight, so every timer the server ran becomes a system schedule the admin panel shows and manages, and administrators create their own. - SchedulerHost runs the shared Scheduler on the job engine (started after JobEngineHost, stopped before it); ServerScheduleHost gives it the container's time zone (UTC with a warning when TZ is unknown), the archive refreshed from archive.json at every run (what ArchivePolling did), the clean-up steps and the system schedules: archive-scan every 10 minutes (no catch-up, also run once at start like the polling), upload-cleanup every 30 minutes, index-backup at 03:00 (SQLite only), housekeeping (job history) at 04:00 and audit-cleanup at 04:30. - ArchivePolling and DatabaseBackupService are gone; UploadMaintenance only recovers commits at start, its sweep is the "uploads" clean-up step. - /api/v1/schedules (ManageArchive, audited): list with actions and time zone, create, PUT/PATCH, delete (409 schedule_system), run now (409 schedule_pending), reset (409 schedule_no_defaults), runs paged by cursor; invalid fields are 400 invalid_schedule naming the field. - CHRONOS_AUDIT_RETENTION_DAYS (AuditRetentionDays, default 365) seeds the audit clean-up; set by the environment it is applied at every start and locked. Job history leaves Settings: it is the housekeeping schedule's age limit, and the setting is what a reset restores. - Admin panel: Jobs has Queue and Scheduled tabs; schedules with when (in the panel's language and the server's zone), next run, last result, a switch, Run now, Edit, Delete or Reset, their runs linking to the jobs, and a side panel for the action, recurrence and parameters; job rows a schedule queued carry a Scheduled pill. Strings in en and it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 808ce94ae29e3bf4522cb4d40dfd76d4f8529c64)
This commit is contained in:
1 parent
e5508e7e69
commit
75daab7275
66 files changed
+1985
-290
No files matched your search
@@ -216,6 +216,34 @@ public sealed class JobRepository
|
||||
_db.ListAsync($"SELECT {Columns} FROM jobs WHERE schedule_id = $1 ORDER BY created DESC, id DESC LIMIT $2",
|
||||
[scheduleId, Cursor.ClampLimit(limit)], Map, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// The jobs the schedule <paramref name="scheduleId"/> queued, newest first, a page at a time (the runs a schedule's
|
||||
/// row lists in the admin panel); <paramref name="cursor"/> continues after the previous page.
|
||||
/// </summary>
|
||||
public Task<Page<Job>> PageByScheduleAsync(Guid scheduleId, int limit = 20, string? cursor = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var p = new SqlParameters();
|
||||
var where = $"schedule_id = {p.Add(scheduleId)}";
|
||||
if (cursor is not null)
|
||||
{
|
||||
var (value, id) = Cursor.Decode("schedule-runs", cursor);
|
||||
where += " AND " + Cursor.After("created", "id", descending: true, value, id, p.Add);
|
||||
}
|
||||
var take = Cursor.ClampLimit(limit);
|
||||
var sql = $"SELECT {Columns} FROM jobs WHERE {where} ORDER BY created DESC, id DESC LIMIT {p.Add(take + 1)}";
|
||||
return _db.RunAsync(async session =>
|
||||
{
|
||||
var jobs = await session.QueryListAsync(sql, p.ToArray(), Map, cancellationToken).ConfigureAwait(false);
|
||||
string? next = null;
|
||||
if (jobs.Count > take)
|
||||
{
|
||||
jobs.RemoveAt(take);
|
||||
next = Cursor.Encode("schedule-runs", jobs[^1].Created, jobs[^1].Id);
|
||||
}
|
||||
return new Page<Job>(jobs, next);
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Claims one specific queued job for <paramref name="nodeId"/> (render nodes pick by capability); null when another
|
||||
/// claimer was faster or the job is no longer queued.
|
||||
|
||||
Reference in new issue
Block a user