Files
Chronos/src/Chronos.Data/Scheduling/IScheduleHost.cs
T
Alby96 e5508e7e69 feat(data): scheduler engine, schedules table and housekeeping jobs
Owner review 2, R10: every timer that queues work becomes a visible schedule,
so the server and the desktop need one shared engine to run them.

- Migration 0007: schedules table (system rows keyed by system_key) and
  jobs.schedule_id; Job.ScheduleId, JobDto.ScheduleId, JobRepository
  HasPendingAsync / ListPendingTargetsAsync / ListByScheduleAsync.
- ScheduleRepository: seeding that keeps user edits, reset, compare-and-set
  claim of a run (one winner across processes), outcomes.
- Scheduling: in-house recurrence (every/daily/weekly/monthly, DST gap moves
  forward, ambiguous time runs once), ScheduleActions resolving scan, verify,
  thumbnails, proxies, analysis, maintenance, backup, cleanup, duplicates and
  orphans into archive jobs, IScheduleHost, and the Scheduler loop (catch-up,
  clock going back, run now, CRUD as API v1 DTOs).
- New job kinds Backup (16) and Cleanup (17) with handlers, shared clean-up
  steps (job history, audit log, trash report that never deletes) and host
  steps through ArchiveServiceOptions; read-only Duplicates and Orphans report
  handlers, so the server can run those kinds too.
- JobEngine no longer purges history at start: the housekeeping schedule's
  job-history step does; JobEngine.CanRun and an EnqueueAsync with scheduleId.
- Protocol DTOs for schedules; job kind names in en and it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit eb0edd2483a493db7c6945d5b494461cabb2a4ad)
2026-10-27 02:08:11 +01:00

53 lines
2.5 KiB
C#

using Chronos.Core.Model;
using Chronos.Protocol;
namespace Chronos.Data.Scheduling;
/// <summary>
/// What a host (the server, the desktop) tells its <see cref="Scheduler"/> (owner review 2, R10): its time zone, the archive
/// schedules work on, the system schedules standing for its timers, the clean-up steps its jobs run, and the actions it
/// cannot run. Called from the scheduler's loop, off any UI thread; members must be thread-safe.
/// </summary>
public interface IScheduleHost
{
/// <summary>The zone of daily, weekly and monthly times: the PC's on the desktop, the container's (TZ) on the server.</summary>
TimeZoneInfo TimeZone { get; }
/// <summary>
/// The archive schedules targeting <c>current</c> work on (the server's archive, the desktop's current one), with its
/// settings as fresh as the host keeps them; null when there is none yet or it cannot be reached. The scheduler probes
/// whether it is online itself.
/// </summary>
ValueTask<Archive?> GetArchiveAsync(CancellationToken cancellationToken);
/// <summary>
/// The system schedules: every timer that queues work on this host, as a visible schedule. Seeded at start by key and
/// never overwritten (the user's edits stay); <see cref="Scheduler.ResetAsync"/> puts one back to these values.
/// </summary>
IReadOnlyList<SystemSchedule> SystemSchedules { get; }
/// <summary>The names of the clean-up steps this host's <see cref="JobKind.Cleanup"/> jobs run (normally those of <c>ArchiveService.CleanupSteps</c>).</summary>
IReadOnlyList<string> CleanupSteps { get; }
/// <summary>
/// Why this host does not run <paramref name="action"/> (a short code, e.g. <c>not-here</c>), or null when it may. Asked
/// before the scheduler's own checks (<see cref="ScheduleUnavailable"/>), for the action list and at every run.
/// </summary>
string? Unavailable(string action);
}
/// <summary>
/// A host's system schedule: <paramref name="SystemKey"/> identifies it across starts (<c>archive-scan</c>,
/// <c>index-backup</c>, <c>housekeeping</c>…); the rest is what it is seeded with and reset to. <paramref name="Name"/> is
/// stored as given; clients show system schedules by their key in the user's language.
/// </summary>
public sealed record SystemSchedule(
string SystemKey,
string Name,
string Action,
ScheduleRecurrence Recurrence,
ScheduleParametersDto? Parameters = null,
bool Enabled = true,
bool CatchUp = true,
JobPriority Priority = JobPriority.Background);