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>
212 lines
8.6 KiB
C#
212 lines
8.6 KiB
C#
using System.Windows.Input;
|
||
using Chronos.App.Infrastructure;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Core.Model;
|
||
using Chronos.Data.Jobs;
|
||
using Chronos.Protocol;
|
||
using Chronos.Ui.Controls;
|
||
using Chronos.Ui.Mvvm;
|
||
|
||
namespace Chronos.App.Jobs;
|
||
|
||
/// <summary>
|
||
/// One row of Jobs › Scheduled (owner review 2, R10): the on/off switch, name, action, when it runs, the next run and the
|
||
/// last result, and its commands (Run now, Edit, then Reset for a system schedule or Delete for one the user created).
|
||
/// </summary>
|
||
public sealed class ScheduleRowViewModel : ObservableObject
|
||
{
|
||
private readonly SchedulesViewModel _owner;
|
||
private ScheduleDto _schedule;
|
||
private Job? _lastJob;
|
||
private long _lastJobStamp;
|
||
private bool _isEnabled;
|
||
|
||
internal ScheduleRowViewModel(ScheduleDto schedule, SchedulesViewModel owner)
|
||
{
|
||
_schedule = schedule;
|
||
_owner = owner;
|
||
_isEnabled = schedule.Enabled;
|
||
RunNowCommand = new AsyncRelayCommand(() => owner.RunNowAsync(this), () => IsAvailable);
|
||
EditCommand = new RelayCommand(() => owner.Edit(this));
|
||
DeleteCommand = new AsyncRelayCommand(() => owner.DeleteAsync(this), () => !IsSystem);
|
||
ResetCommand = new AsyncRelayCommand(() => owner.ResetAsync(this), () => IsSystem);
|
||
}
|
||
|
||
public ScheduleDto Schedule => _schedule;
|
||
public Guid Id => _schedule.Id;
|
||
|
||
/// <summary>A system schedule: one of the host's timers, reset instead of deleted.</summary>
|
||
public bool IsSystem => _schedule.SystemKey is not null;
|
||
|
||
/// <summary>The job the last run queued, when it is known.</summary>
|
||
public Job? LastJob => _lastJob;
|
||
|
||
public string Name => ScheduleText.Name(_schedule);
|
||
|
||
public string NameToolTip => IsSystem ? Loc.L("Tooltips.Jobs.Schedule.System", Name) : Name;
|
||
|
||
public string ActionText => ScheduleText.Action(_schedule.Action);
|
||
|
||
/// <summary>What the action does, or why this PC does not run it.</summary>
|
||
public string ActionToolTip => IsAvailable ? ScheduleText.ActionToolTip(_schedule.Action) : ScheduleText.Unavailable(_owner.UnavailableReason(_schedule.Action));
|
||
|
||
/// <summary>This PC runs the schedule's action.</summary>
|
||
public bool IsAvailable => _owner.IsAvailable(_schedule.Action);
|
||
|
||
public string WhenText => ScheduleText.When(_schedule.Recurrence);
|
||
|
||
/// <summary>When it runs, whether a missed run is caught up, and the priority of its jobs.</summary>
|
||
public string WhenToolTip => string.Join(Loc.Separator, WhenText,
|
||
Loc.L(_schedule.CatchUp ? "Tooltips.Jobs.Schedule.CatchUpOn" : "Tooltips.Jobs.Schedule.CatchUpOff"),
|
||
Loc.L("Tooltips.Jobs.Schedule.PriorityIs", ScheduleText.Priority(Priority)));
|
||
|
||
public string NextText => ScheduleText.Next(_schedule.NextRun, _schedule.Enabled);
|
||
|
||
public string NextToolTip => !_schedule.Enabled ? Loc.L("Tooltips.Jobs.Schedule.NextOff")
|
||
: _schedule.NextRun is { } next ? Loc.L("Tooltips.Jobs.Schedule.Next", Formatting.Date(next) + " " + Formatting.TimeOfDay(next))
|
||
: Loc.L("Tooltips.Jobs.Schedule.NextPending");
|
||
|
||
public string LastText => ScheduleText.Outcome(_schedule.LastOutcome, _lastJob);
|
||
|
||
public string LastToolTip => ScheduleText.OutcomeToolTip(_schedule.LastOutcome, _schedule.LastRun, _lastJob);
|
||
|
||
public StatusKind LastKind => ScheduleText.OutcomeKind(_schedule.LastOutcome, _lastJob);
|
||
|
||
/// <summary>Off, a schedule never runs by itself (Run now still runs it). Turning it on or off saves at once.</summary>
|
||
public bool IsEnabled
|
||
{
|
||
get => _isEnabled;
|
||
set
|
||
{
|
||
if (Set(ref _isEnabled, value)) _ = _owner.SetEnabledAsync(this, value);
|
||
}
|
||
}
|
||
|
||
public string EnabledToolTip => Loc.L(_isEnabled ? "Tooltips.Jobs.Schedule.EnabledOn" : "Tooltips.Jobs.Schedule.EnabledOff");
|
||
|
||
/// <summary>"Index backup · Index backup · Daily at 03:00": the row's name for screen readers.</summary>
|
||
public string AccessibleName => string.Join(Loc.Separator, Name, ActionText, WhenText);
|
||
|
||
public ICommand RunNowCommand { get; }
|
||
public ICommand EditCommand { get; }
|
||
public ICommand DeleteCommand { get; }
|
||
public ICommand ResetCommand { get; }
|
||
|
||
public string RunNowToolTip => IsAvailable ? Loc.L("Tooltips.Jobs.Schedule.RunNow") : ScheduleText.Unavailable(_owner.UnavailableReason(_schedule.Action));
|
||
|
||
/// <summary>"Run now: Index backup", what each row button is called for screen readers.</summary>
|
||
public string RunNowName => Loc.L("Jobs.ActionFor", Loc.L("Jobs.Schedule.RunNow"), Name);
|
||
public string EditName => Loc.L("Jobs.ActionFor", Loc.L("Jobs.Schedule.Edit"), Name);
|
||
public string DeleteName => Loc.L("Jobs.ActionFor", Loc.L("Jobs.Schedule.Delete"), Name);
|
||
public string ResetName => Loc.L("Jobs.ActionFor", Loc.L("Jobs.Schedule.Reset"), Name);
|
||
public string EnabledName => Loc.L("Jobs.ActionFor", Loc.L("Jobs.Schedule.Enabled"), Name);
|
||
|
||
private JobPriority Priority => JobWire.TryParsePriority(_schedule.Priority, out var priority) ? priority : JobPriority.Background;
|
||
|
||
/// <summary>A newer copy of the schedule (an edit, a run, a correction of its next run).</summary>
|
||
internal void Update(ScheduleDto schedule)
|
||
{
|
||
if (schedule.LastJobId != _schedule.LastJobId)
|
||
{
|
||
// A read of the previous job no longer applies.
|
||
_lastJob = null;
|
||
_lastJobStamp++;
|
||
}
|
||
_schedule = schedule;
|
||
_isEnabled = schedule.Enabled;
|
||
OnAllPropertiesChanged();
|
||
}
|
||
|
||
/// <summary>The job the last run queued changed (live, from the engine): the last result follows its state.</summary>
|
||
internal void SetLastJob(Job? job)
|
||
{
|
||
if (job is not null && job.Id != _schedule.LastJobId) return;
|
||
_lastJobStamp++;
|
||
ShowLastJob(job);
|
||
}
|
||
|
||
/// <summary>
|
||
/// A read of the last job from the index starts; its result applies only while nothing newer arrived (a live change,
|
||
/// another job, a later read): see <see cref="SetLoadedLastJob"/>.
|
||
/// </summary>
|
||
internal long BeginLastJobRead() => ++_lastJobStamp;
|
||
|
||
/// <summary>The last job as the read begun at <paramref name="read"/> found it; ignored when that read is stale.</summary>
|
||
internal void SetLoadedLastJob(Job? job, long read)
|
||
{
|
||
if (read != _lastJobStamp || (job is not null && job.Id != _schedule.LastJobId)) return;
|
||
ShowLastJob(job);
|
||
}
|
||
|
||
private void ShowLastJob(Job? job)
|
||
{
|
||
_lastJob = job;
|
||
OnPropertyChanged(nameof(LastJob));
|
||
OnPropertyChanged(nameof(LastText));
|
||
OnPropertyChanged(nameof(LastToolTip));
|
||
OnPropertyChanged(nameof(LastKind));
|
||
}
|
||
|
||
/// <summary>The switch goes back to the stored state (the change was refused).</summary>
|
||
internal void RevertEnabled()
|
||
{
|
||
_isEnabled = _schedule.Enabled;
|
||
OnPropertyChanged(nameof(IsEnabled));
|
||
OnPropertyChanged(nameof(EnabledToolTip));
|
||
}
|
||
|
||
internal void Refresh() => OnAllPropertiesChanged();
|
||
}
|
||
|
||
/// <summary>A job a schedule queued, in the selected schedule's last runs: kind, target, when, state, and Show in queue.</summary>
|
||
public sealed class ScheduleRunViewModel : ObservableObject
|
||
{
|
||
private Job _job;
|
||
|
||
internal ScheduleRunViewModel(Job job, Func<Guid, Task> show)
|
||
{
|
||
_job = job;
|
||
ShowCommand = new AsyncRelayCommand(() => show(_job.Id));
|
||
}
|
||
|
||
public Job Job => _job;
|
||
public Guid Id => _job.Id;
|
||
|
||
public string Kind => JobText.Kind(_job.Kind);
|
||
|
||
public string Target => _job.TargetLabel ?? string.Empty;
|
||
|
||
/// <summary>When the run queued it ("Today 03:00").</summary>
|
||
public string WhenText => ScheduleText.Moment(_job.Created);
|
||
|
||
public string StateText => JobText.State(new JobEntry(_job));
|
||
|
||
public string StateToolTip => string.Join(Loc.Separator, StateText,
|
||
_job.Error is { Length: > 0 } error ? error : Loc.L("Tooltips.Jobs.State." + _job.State));
|
||
|
||
public StatusKind StateKind => _job.State switch
|
||
{
|
||
JobState.Running => StatusKind.Running,
|
||
JobState.Queued => StatusKind.Queued,
|
||
JobState.Paused => StatusKind.Paused,
|
||
JobState.Done => StatusKind.Done,
|
||
JobState.Failed => StatusKind.Failed,
|
||
_ => StatusKind.Offline,
|
||
};
|
||
|
||
/// <summary>"Verify · Archive · 2024: done": the row for screen readers.</summary>
|
||
public string AccessibleName => Loc.L("Jobs.Row.State", JobText.Name(_job), StateText);
|
||
|
||
public string ShowName => Loc.L("Jobs.ActionFor", Loc.L("Jobs.Schedule.ShowJob"), JobText.Name(_job));
|
||
|
||
public ICommand ShowCommand { get; }
|
||
|
||
internal void Update(Job job)
|
||
{
|
||
_job = job;
|
||
OnAllPropertiesChanged();
|
||
}
|
||
|
||
internal void Refresh() => OnAllPropertiesChanged();
|
||
}
|