fix(app): keep Jobs › Scheduled true to the scheduler
Owner review 2, phase 2 (R10) review findings on the desktop: - Showing the Scheduled tab (and coming back to Jobs on it) reads the actions' availability again, as does a Run now answered unavailable; rows and an open editor follow, so turning proxies on no longer needs a restart. - A delete the index refuses keeps the row: the failed call no longer reads as Deleted (the enum's default), so a live schedule never leaves the page. - SchedulerReady completes false when the index (or the engine) does not open, so the tab shows that the schedules do not run instead of an empty panel. - A read of a schedule's last job that started before a live change or a later read is ignored, so a finished job no longer shows as running. - The editor's Action, Unit and Priority dropdowns follow a language change, keeping what was chosen. - Weekly days in the table read from the UI language's first day, as the editor's toggles do. - Backup tooltips no longer promise daily copies with three kept (their translations are dropped for retranslation); two tooltips now name the real Settings rows (Proxy size; Spazio su disco › Limite della cache). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c137e2c74cddef299b2e4179ef0417fa4977953c)
This commit is contained in:
1 parent
3f0e6357b1
commit
5cb6809fd0
14 files changed
+361
-33
No files matched your search
@@ -432,7 +432,7 @@
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.NoIndexFile" xml:space="preserve"><value>The index has no file to copy</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.Other" xml:space="preserve"><value>Not available on this PC</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.Postgres" xml:space="preserve"><value>The index is on PostgreSQL, which its own tools back up</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled" xml:space="preserve"><value>The archive makes no proxies (Settings › Archive › Proxies)</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled" xml:space="preserve"><value>The archive makes no proxies (Settings › Archive › Proxy size)</value></data>
|
||||
<data name="Tooltips.Jobs.Scheduled" xml:space="preserve"><value>Queued by a schedule (Scheduled tab)</value></data>
|
||||
<data name="Tooltips.Jobs.Search" xml:space="preserve"><value>Filter by target or kind as you type</value></data>
|
||||
<data name="Tooltips.Jobs.Show" xml:space="preserve"><value>Open what this job worked on to see the problem</value></data>
|
||||
@@ -625,8 +625,8 @@
|
||||
<data name="Tooltips.Settings.AnalysisWidth" xml:space="preserve"><value>Largest long edge frames are decoded at for deep analysis (half the native size up to this); wider is slower and sees finer detail</value></data>
|
||||
<data name="Tooltips.Settings.ArchiveFree" xml:space="preserve"><value>Free space on the archive drive</value></data>
|
||||
<data name="Tooltips.Settings.ArchiveRoot" xml:space="preserve"><value>Root of the local archive; files are not moved · Enter applies, Esc reverts</value></data>
|
||||
<data name="Tooltips.Settings.Backup" xml:space="preserve"><value>Copy the index to the backups folder, which keeps as many copies as the backup schedules in Jobs › Scheduled · a few seconds</value></data>
|
||||
<data name="Tooltips.Settings.Backups" xml:space="preserve"><value>Copies of the index made by the backup schedules and Back up now; choose the one to return to</value></data>
|
||||
<data name="Tooltips.Settings.Backup" xml:space="preserve"><value>Copy the index to the backups folder, which keeps as many copies as the backup schedules in Jobs › Scheduled keep · a few seconds</value></data>
|
||||
<data name="Tooltips.Settings.Backups" xml:space="preserve"><value>Copies of the index made by the Index backup schedule (Jobs › Scheduled) or Back up now; choose the one to return to</value></data>
|
||||
<data name="Tooltips.Settings.BrowseArchive" xml:space="preserve"><value>Choose the archive folder</value></data>
|
||||
<data name="Tooltips.Settings.BrowseCache" xml:space="preserve"><value>Choose the cache folder; a fast SSD helps</value></data>
|
||||
<data name="Tooltips.Settings.CacheFolder" xml:space="preserve"><value>Where frames spill and thumbnails are kept; a fast SSD helps · Enter applies, Esc reverts</value></data>
|
||||
|
||||
@@ -423,7 +423,7 @@
|
||||
<data name="Tooltips.Jobs.Schedule.Runs" xml:space="preserve"><value>Le attività che questa pianificazione ha messo in coda, dalla più recente</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.ShowJob" xml:space="preserve"><value>Mostra questa attività nella coda con il suo log</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Step.Audit" xml:space="preserve"><value>Rimuove le voci del registro di controllo più vecchie del limite</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Step.CacheTrim" xml:space="preserve"><value>Riduce la cache a Impostazioni › Archiviazione › Limite cache, prima i file più vecchi</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Step.CacheTrim" xml:space="preserve"><value>Riduce la cache a Impostazioni › Spazio su disco › Limite della cache, prima i file più vecchi</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Step.JobHistory" xml:space="preserve"><value>Rimuove le attività concluse più vecchie del limite</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Step.TrashReport" xml:space="preserve"><value>Elenca le voci del cestino più vecchie del limite; non elimina niente</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.System" xml:space="preserve"><value>{0} è una pianificazione propria di questo PC: si può modificare, disattivare o ripristinare, non eliminare</value></data>
|
||||
@@ -431,7 +431,7 @@
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.NoIndexFile" xml:space="preserve"><value>L'indice non ha un file da copiare</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.Other" xml:space="preserve"><value>Non disponibile su questo PC</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.Postgres" xml:space="preserve"><value>L'indice è su PostgreSQL, che si copia con i propri strumenti</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled" xml:space="preserve"><value>L'archivio non crea proxy (Impostazioni › Archivio › Proxy)</value></data>
|
||||
<data name="Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled" xml:space="preserve"><value>L'archivio non crea proxy (Impostazioni › Archivio › Dimensione proxy)</value></data>
|
||||
<data name="Tooltips.Jobs.Scheduled" xml:space="preserve"><value>Messa in coda da una pianificazione (scheda Pianificate)</value></data>
|
||||
<data name="Tooltips.Jobs.Search" xml:space="preserve"><value>Filtra per oggetto o tipo mentre scrivi</value></data>
|
||||
<data name="Tooltips.Jobs.Show" xml:space="preserve"><value>Apre l'oggetto dell'attività per vedere il problema</value></data>
|
||||
@@ -623,8 +623,8 @@
|
||||
<data name="Tooltips.Settings.AnalysisWidth" xml:space="preserve"><value>Lato lungo massimo dei fotogrammi decodificati per l'analisi profonda (metà della dimensione nativa fino a questo); più largo è più lento e vede dettagli più fini</value></data>
|
||||
<data name="Tooltips.Settings.ArchiveFree" xml:space="preserve"><value>Spazio libero sull'unità dell'archivio</value></data>
|
||||
<data name="Tooltips.Settings.ArchiveRoot" xml:space="preserve"><value>Radice dell'archivio locale; i file non vengono spostati · Invio applica, Esc annulla</value></data>
|
||||
<data name="Tooltips.Settings.Backup" xml:space="preserve"><value>Copia l'indice nella cartella dei backup, che ne tiene quante le copie pianificate in Attività › Pianificate · pochi secondi</value></data>
|
||||
<data name="Tooltips.Settings.Backups" xml:space="preserve"><value>Copie dell'indice fatte dalle copie pianificate e da Salva una copia; scegli quella a cui tornare</value></data>
|
||||
<data name="Tooltips.Settings.Backup" xml:space="preserve"><value>Copia l'indice nella cartella dei backup, che ne conserva quante ne tengono le pianificazioni di copia in Attività › Pianificate · pochi secondi</value></data>
|
||||
<data name="Tooltips.Settings.Backups" xml:space="preserve"><value>Copie dell'indice fatte dalla pianificazione Copia dell'indice (Attività › Pianificate) o da Salva una copia; scegli quella a cui tornare</value></data>
|
||||
<data name="Tooltips.Settings.BrowseArchive" xml:space="preserve"><value>Scegli la cartella dell'archivio</value></data>
|
||||
<data name="Tooltips.Settings.BrowseCache" xml:space="preserve"><value>Scegli la cartella della cache; un SSD veloce aiuta</value></data>
|
||||
<data name="Tooltips.Settings.CacheFolder" xml:space="preserve"><value>Dove vanno i fotogrammi temporanei e le miniature; un SSD veloce aiuta · Invio applica, Esc annulla</value></data>
|
||||
|
||||
@@ -232,7 +232,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
/// <summary>
|
||||
/// Opens (or creates) the index at <paramref name="databasePath"/>, migrates it (after a restore staged in Settings ›
|
||||
/// Advanced replaced it, which needs no open index: it also recovers one that no longer opens), starts the job engine,
|
||||
/// then in the background reopens the archive and starts the schedules (<see cref="SchedulerReady"/>).
|
||||
/// then in the background reopens the archive and starts the schedules (<see cref="SchedulerReady"/>, false at once
|
||||
/// when the index or the engine does not open).
|
||||
/// </summary>
|
||||
public async Task OpenAsync(string databasePath, CancellationToken ct = default)
|
||||
{
|
||||
@@ -246,11 +247,21 @@ public sealed class AppServices : IAsyncDisposable
|
||||
{
|
||||
OpenError = ex;
|
||||
Log.Error("app", "The index could not be opened", ex);
|
||||
// No index, no schedules: Jobs › Scheduled says so instead of waiting for them.
|
||||
_schedulerReady.TrySetResult(false);
|
||||
return;
|
||||
}
|
||||
await StartJobsAsync(Database, startEngine: true, ct);
|
||||
Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems);
|
||||
Devices.Start();
|
||||
try
|
||||
{
|
||||
await StartJobsAsync(Database, startEngine: true, ct);
|
||||
Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems);
|
||||
Devices.Start();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_schedulerReady.TrySetResult(false);
|
||||
throw;
|
||||
}
|
||||
_schedules = RunSchedulesAsync(_stopping.Token);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,10 +141,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
{
|
||||
_owner = owner;
|
||||
_schedule = schedule;
|
||||
var available = owner.Actions;
|
||||
ActionOptions = [.. ScheduleActions.All.Select(a => available.FirstOrDefault(x => x.Name == a) is { } info
|
||||
? new ScheduleActionOption(a, info.Available, info.Reason)
|
||||
: new ScheduleActionOption(a, true, null))];
|
||||
ActionOptions = BuildActionOptions();
|
||||
_action = schedule is not null
|
||||
? ActionOptions.FirstOrDefault(o => o.Name == schedule.Action) ?? new ScheduleActionOption(schedule.Action, false, null)
|
||||
: ActionOptions.FirstOrDefault(o => o.IsAvailable) ?? ActionOptions[0];
|
||||
@@ -154,7 +151,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
// When: the stored recurrence, or every day at 03:00 for a new schedule.
|
||||
var recurrence = ScheduleMapping.FromDto(schedule?.Recurrence) ?? ScheduleRecurrence.DailyAt(new TimeOnly(3, 0));
|
||||
_kindIndex = (int)recurrence.Kind;
|
||||
Units = [.. Enum.GetValues<RecurrenceUnit>().Select(u => new SettingsOption<RecurrenceUnit>(u, Loc.L("Jobs.Editor.Unit." + u)))];
|
||||
Units = BuildUnits();
|
||||
_unit = Units.First(u => u.Value == (recurrence.Kind == RecurrenceKind.Every ? recurrence.Unit : RecurrenceUnit.Hours));
|
||||
Every = new ScheduleField(Number(recurrence.Kind == RecurrenceKind.Every ? recurrence.Every : 6), ValidateEvery, () => Loc.L("Tooltips.Jobs.Editor.Every"));
|
||||
Time = new ScheduleField(recurrence.Time.ToString("HH:mm", CultureInfo.InvariantCulture), ValidateTime, () => Loc.L("Tooltips.Jobs.Editor.Time"));
|
||||
@@ -170,7 +167,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
Keep = new ScheduleField(string.Empty, v => ValidateNumber(v, 1, 100), () => Loc.L("Tooltips.Jobs.Editor.Keep"));
|
||||
LoadParameters(schedule?.Parameters ?? ScheduleActions.Defaults(_action.Name));
|
||||
|
||||
Priorities = [.. new[] { JobPriority.Background, JobPriority.Normal, JobPriority.User }.Select(p => new SettingsOption<JobPriority>(p, ScheduleText.Priority(p)))];
|
||||
Priorities = BuildPriorities();
|
||||
var priority = schedule is not null && JobWire.TryParsePriority(schedule.Priority, out var stored) ? stored : JobPriority.Background;
|
||||
_priority = Priorities.First(p => p.Value == priority);
|
||||
_catchUp = schedule?.CatchUp ?? true;
|
||||
@@ -196,7 +193,8 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
/// <summary>The name shown for a system schedule, which is not edited.</summary>
|
||||
public string SystemName => _schedule is null ? string.Empty : ScheduleText.Name(_schedule);
|
||||
|
||||
public IReadOnlyList<ScheduleActionOption> ActionOptions { get; }
|
||||
/// <summary>Every action, with whether this PC runs it as last read; built again when that or the UI language changes.</summary>
|
||||
public IReadOnlyList<ScheduleActionOption> ActionOptions { get; private set; }
|
||||
|
||||
public ScheduleActionOption SelectedAction
|
||||
{
|
||||
@@ -242,7 +240,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
|
||||
public ScheduleField Every { get; }
|
||||
|
||||
public IReadOnlyList<SettingsOption<RecurrenceUnit>> Units { get; }
|
||||
public IReadOnlyList<SettingsOption<RecurrenceUnit>> Units { get; private set; }
|
||||
|
||||
public SettingsOption<RecurrenceUnit> SelectedUnit
|
||||
{
|
||||
@@ -320,7 +318,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
|
||||
// ---------------- Options ----------------
|
||||
|
||||
public IReadOnlyList<SettingsOption<JobPriority>> Priorities { get; }
|
||||
public IReadOnlyList<SettingsOption<JobPriority>> Priorities { get; private set; }
|
||||
|
||||
public SettingsOption<JobPriority> SelectedPriority
|
||||
{
|
||||
@@ -434,14 +432,52 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
|
||||
internal UpdateScheduleRequest BuildUpdate() =>
|
||||
new(IsSystem ? null : Name.Text.Trim(), IsSystem ? null : _action.Name, Recurrence(), Parameters(), _catchUp, JobWire.Priority(_priority.Value), _enabled);
|
||||
|
||||
/// <summary>Whether this PC runs each action was read again (<see cref="SchedulesViewModel.RefreshActionsAsync"/>).</summary>
|
||||
internal void RefreshActions() => RebuildActionOptions();
|
||||
|
||||
protected override void OnLanguageChanged()
|
||||
{
|
||||
foreach (var field in new[] { Name, Every, Time, DayOfMonth, OlderThan, Percent, Keep }) field.Refresh();
|
||||
foreach (var day in Days) day.Refresh();
|
||||
foreach (var step in Steps) step.Refresh();
|
||||
// The dropdowns' choices carry their labels: new ones in the new language, the same values chosen. Each list is
|
||||
// announced before its choice, so a dropdown finds the choice among its items.
|
||||
RebuildActionOptions();
|
||||
Units = BuildUnits();
|
||||
_unit = Units.First(u => u.Value == _unit.Value);
|
||||
OnPropertyChanged(nameof(Units));
|
||||
OnPropertyChanged(nameof(SelectedUnit));
|
||||
Priorities = BuildPriorities();
|
||||
_priority = Priorities.First(p => p.Value == _priority.Value);
|
||||
OnPropertyChanged(nameof(Priorities));
|
||||
OnPropertyChanged(nameof(SelectedPriority));
|
||||
base.OnLanguageChanged();
|
||||
}
|
||||
|
||||
/// <summary>The actions again, from the owner's last read; the chosen one stays chosen.</summary>
|
||||
private void RebuildActionOptions()
|
||||
{
|
||||
ActionOptions = BuildActionOptions();
|
||||
_action = ActionOptions.FirstOrDefault(o => o.Name == _action.Name) ?? _action;
|
||||
OnPropertyChanged(nameof(ActionOptions));
|
||||
OnPropertyChanged(nameof(SelectedAction));
|
||||
OnPropertyChanged(nameof(ActionToolTip));
|
||||
}
|
||||
|
||||
private ScheduleActionOption[] BuildActionOptions()
|
||||
{
|
||||
var available = _owner.Actions;
|
||||
return [.. ScheduleActions.All.Select(a => available.FirstOrDefault(x => x.Name == a) is { } info
|
||||
? new ScheduleActionOption(a, info.Available, info.Reason)
|
||||
: new ScheduleActionOption(a, true, null))];
|
||||
}
|
||||
|
||||
private static SettingsOption<RecurrenceUnit>[] BuildUnits() =>
|
||||
[.. Enum.GetValues<RecurrenceUnit>().Select(u => new SettingsOption<RecurrenceUnit>(u, Loc.L("Jobs.Editor.Unit." + u)))];
|
||||
|
||||
private static SettingsOption<JobPriority>[] BuildPriorities() =>
|
||||
[.. new[] { JobPriority.Background, JobPriority.Normal, JobPriority.User }.Select(p => new SettingsOption<JobPriority>(p, ScheduleText.Priority(p)))];
|
||||
|
||||
private bool IsVerify => _action.Name == ScheduleActions.Verify;
|
||||
|
||||
/// <summary>Save: the schedule as the fields hold it; the editor closes once it is stored, or says why it was not.</summary>
|
||||
|
||||
@@ -18,6 +18,7 @@ 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)
|
||||
@@ -105,16 +106,40 @@ public sealed class ScheduleRowViewModel : ObservableObject
|
||||
/// <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) _lastJob = null;
|
||||
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 (or was read): the last result follows its state.</summary>
|
||||
/// <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));
|
||||
|
||||
@@ -62,9 +62,15 @@ public static class ScheduleText
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>"Mon, Thu": the days in the order of the week, short names of the UI language.</summary>
|
||||
public static string Days(IEnumerable<DayOfWeek> days) =>
|
||||
days.Select(DayShort).Aggregate((a, b) => Loc.L("Jobs.Schedule.DayList", a, b));
|
||||
/// <summary>
|
||||
/// "Mon, Thu": the days in the order of the UI language's week, from its first day as the editor lists them (Sunday
|
||||
/// first in English, Monday first in Italian), short names of the UI language.
|
||||
/// </summary>
|
||||
public static string Days(IEnumerable<DayOfWeek> days)
|
||||
{
|
||||
var first = (int)Loc.Culture.DateTimeFormat.FirstDayOfWeek;
|
||||
return days.OrderBy(d => ((int)d - first + 7) % 7).Select(DayShort).Aggregate((a, b) => Loc.L("Jobs.Schedule.DayList", a, b));
|
||||
}
|
||||
|
||||
/// <summary>"Mon" in the UI language.</summary>
|
||||
public static string DayShort(DayOfWeek day) => Loc.Culture.DateTimeFormat.GetAbbreviatedDayName(day);
|
||||
|
||||
@@ -241,6 +241,30 @@ public sealed class SchedulesViewModel : LocalizedViewModel
|
||||
if (_selected is not null) await LoadRunsAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads again whether this PC runs each action (Jobs › Scheduled is shown: proxies may have been turned on or off,
|
||||
/// another archive chosen): the rows' Run now and tooltips, and the actions of the editor, follow it.
|
||||
/// </summary>
|
||||
public async Task RefreshActionsAsync()
|
||||
{
|
||||
if (_attached is not { } scheduler) return;
|
||||
SchedulesDto list;
|
||||
try
|
||||
{
|
||||
list = await Task.Run(() => scheduler.ListAsync());
|
||||
}
|
||||
catch (Exception ex) when (ex is DatabaseException or IOException or InvalidOperationException)
|
||||
{
|
||||
Log.Warning("schedules", "The actions could not be read again", ex);
|
||||
return;
|
||||
}
|
||||
_actions = list.Actions;
|
||||
_steps = list.Steps ?? [];
|
||||
foreach (var row in Rows) row.Refresh();
|
||||
_editor?.RefreshActions();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
/// <summary>A job changed (UI thread, from the Jobs screen's flush): the last result and the last runs follow it.</summary>
|
||||
public void OnJob(Job job)
|
||||
{
|
||||
@@ -287,6 +311,8 @@ public sealed class SchedulesViewModel : LocalizedViewModel
|
||||
}
|
||||
Apply(run.Schedule);
|
||||
if (run.Outcome == ScheduleOutcome.Queued) return;
|
||||
// This PC no longer runs the action: the row says so from now on.
|
||||
if (run.Outcome == ScheduleOutcome.Unavailable) await RefreshActionsAsync();
|
||||
_notify(Loc.L("Jobs.Row.Name", row.Name, ScheduleText.Outcome(run.Outcome, null)), ScheduleText.OutcomeToolTip(run.Outcome, run.Schedule.LastRun, null),
|
||||
ScheduleOutcome.IsFailed(run.Outcome, out _) || run.Outcome == ScheduleOutcome.Unavailable);
|
||||
}
|
||||
@@ -326,7 +352,8 @@ public sealed class SchedulesViewModel : LocalizedViewModel
|
||||
IsDestructive = true,
|
||||
});
|
||||
if (!confirmed) return;
|
||||
var outcome = await Call(() => scheduler.DeleteAsync(row.Id));
|
||||
// Nullable: a failed call is null, not the enum's first value (Deleted), so its row stays.
|
||||
var outcome = await Call<ScheduleDeleteOutcome?>(async () => await scheduler.DeleteAsync(row.Id));
|
||||
if (outcome is ScheduleDeleteOutcome.Deleted or ScheduleDeleteOutcome.NotFound) Remove(row.Id);
|
||||
}
|
||||
|
||||
@@ -443,12 +470,14 @@ public sealed class SchedulesViewModel : LocalizedViewModel
|
||||
RaiseState();
|
||||
}
|
||||
|
||||
/// <summary>Reads the job of the schedule's last run; a change of it announced meanwhile, or a later read, wins.</summary>
|
||||
private async Task LoadLastJobAsync(ScheduleRowViewModel row)
|
||||
{
|
||||
if (row.Schedule.LastJobId is not { } id || _database() is not { } db) return;
|
||||
var read = row.BeginLastJobRead();
|
||||
try
|
||||
{
|
||||
row.SetLastJob(await db.Jobs.GetAsync(id));
|
||||
row.SetLoadedLastJob(await db.Jobs.GetAsync(id), read);
|
||||
}
|
||||
catch (DatabaseException ex)
|
||||
{
|
||||
@@ -479,7 +508,10 @@ public sealed class SchedulesViewModel : LocalizedViewModel
|
||||
RaiseRuns();
|
||||
}
|
||||
|
||||
/// <summary>Runs a scheduler call off the UI thread; a failure becomes a toast and null.</summary>
|
||||
/// <summary>
|
||||
/// Runs a scheduler call off the UI thread; a failure becomes a toast and null (for a value type, ask for its nullable
|
||||
/// type: its default would read as a result).
|
||||
/// </summary>
|
||||
private async Task<T?> Call<T>(Func<Task<T>> call)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -189,7 +189,7 @@ public sealed class ArchiveViewModel : SectionViewModel
|
||||
|
||||
public ICommand BackupCommand { get; }
|
||||
|
||||
/// <summary>"Maintenance ▾ › Restore database…" (BRIEF §12.5): Settings › Advanced, where a daily copy is compared and restored (§6.2).</summary>
|
||||
/// <summary>"Maintenance ▾ › Restore database…" (BRIEF §12.5): Settings › Advanced, where a backup copy is compared and restored (§6.2).</summary>
|
||||
public ICommand RestoreCommand { get; }
|
||||
|
||||
public ICommand MaintenanceCommand { get; }
|
||||
|
||||
@@ -113,7 +113,7 @@ public sealed class JobsViewModel : SectionViewModel
|
||||
/// <summary>Jobs › Scheduled.</summary>
|
||||
public SchedulesViewModel Schedules { get; }
|
||||
|
||||
/// <summary>0 = Queue, 1 = Scheduled (the segmented control's index).</summary>
|
||||
/// <summary>0 = Queue, 1 = Scheduled (the segmented control's index). Scheduled, shown, reads the actions' availability again.</summary>
|
||||
public int TabIndex
|
||||
{
|
||||
get => _tabIndex;
|
||||
@@ -122,6 +122,7 @@ public sealed class JobsViewModel : SectionViewModel
|
||||
if (value is < 0 or > 1 || !Set(ref _tabIndex, value)) return;
|
||||
OnPropertyChanged(nameof(IsQueue));
|
||||
OnPropertyChanged(nameof(IsScheduled));
|
||||
if (IsScheduled) _ = Schedules.RefreshActionsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,9 +280,13 @@ public sealed class JobsViewModel : SectionViewModel
|
||||
UpdateShell();
|
||||
}
|
||||
|
||||
/// <summary>Failures seen on this screen no longer count on the rail.</summary>
|
||||
/// <summary>
|
||||
/// Failures seen on this screen no longer count on the rail; back on Scheduled (from Settings, say), the actions'
|
||||
/// availability is read again.
|
||||
/// </summary>
|
||||
protected override void OnActivated()
|
||||
{
|
||||
if (IsScheduled) _ = Schedules.RefreshActionsAsync();
|
||||
if (_unseenFailures.Count == 0) return;
|
||||
_unseenFailures.Clear();
|
||||
UpdateShell();
|
||||
|
||||
@@ -646,7 +646,7 @@
|
||||
<Button HorizontalAlignment="Left" Content="{l:Loc Settings.Advanced.BackupNow}" Command="{Binding BackupDatabaseCommand}" ToolTip="{l:Loc Tooltips.Settings.Backup}"
|
||||
ui:ButtonIcon.Glyph="{StaticResource Icon.Database}" />
|
||||
</HeaderedContentControl>
|
||||
<!-- Restore: a daily copy, its dry run and confirmation; it replaces the index at the next start. -->
|
||||
<!-- Restore: a backup copy of the index, its dry run and confirmation; it replaces the index at the next start. -->
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Advanced.Restore}">
|
||||
<WrapPanel>
|
||||
<TextBlock Style="{StaticResource Text.Hint}" Text="{l:Loc Settings.Advanced.NoBackups}" Margin="0,0,12,0"
|
||||
|
||||
@@ -762,7 +762,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
public ICommand ExportDiagnosticsCommand { get; }
|
||||
public ICommand BackupDatabaseCommand { get; }
|
||||
|
||||
/// <summary>The copies of the index in the backups folder, newest first (Restore).</summary>
|
||||
/// <summary>The copies of the index in the backups folder (the Index backup schedule's, Back up now's), newest first (Restore).</summary>
|
||||
public IReadOnlyList<BackupOption> Backups
|
||||
{
|
||||
get => _backups;
|
||||
|
||||
@@ -121,6 +121,47 @@ public sealed class AppServicesTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Owner review 2, R10: when the index does not open, the schedules are known not to run at once, so Jobs › Scheduled
|
||||
/// says so instead of waiting for them with an empty tab.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public void AnIndexThatDoesNotOpenTellsTheScheduledTabTheSchedulesDoNotRun()
|
||||
{
|
||||
var environment = AppEnvironment.ForCapture();
|
||||
try
|
||||
{
|
||||
SingleThreadedContext.Run(async () =>
|
||||
{
|
||||
// "File is not a database", and no staged restore to recover it.
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(environment.DatabasePath)!);
|
||||
await File.WriteAllBytesAsync(environment.DatabasePath, [.. Enumerable.Repeat((byte)0x5A, 8192)]);
|
||||
var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
|
||||
try
|
||||
{
|
||||
await services.OpenAsync(environment.DatabasePath);
|
||||
Assert.NotNull(services.OpenError);
|
||||
var ready = services.SchedulerReady;
|
||||
Assert.Same(ready, await Task.WhenAny(ready, Task.Delay(TimeSpan.FromSeconds(TestTiming.Budget(10)))));
|
||||
Assert.False(await ready, "no schedules without an index");
|
||||
|
||||
using var schedules = new SchedulesViewModel(() => services.Scheduler, () => services.Database, _ => false, (_, _, _) => { }, _ => Task.CompletedTask);
|
||||
await schedules.AttachAsync(services.SchedulerReady);
|
||||
Assert.True(schedules.IsLoaded && schedules.IsUnavailable && !schedules.IsRunning, "the tab shows that the schedules do not run");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
environment.DeleteCaptureData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>BRIEF §6.2: a restore staged in Settings › Advanced recovers an index that no longer opens.</summary>
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Globalization;
|
||||
using Chronos.App.Jobs;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Scheduling;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Jobs › Scheduled in another language (owner review 2, R10). These switch the process-wide UI language, so the class is
|
||||
/// serial: in parallel it would race with the English assertions of the classes running beside it.
|
||||
/// </summary>
|
||||
[Serial]
|
||||
public sealed class ScheduleLanguageTests(TestContext context)
|
||||
{
|
||||
/// <summary>The days of a weekly schedule read in the order of the editor's toggles: from the UI language's first day.</summary>
|
||||
[Test]
|
||||
public void WeeklyDaysFollowTheWeekOfTheUiLanguage()
|
||||
{
|
||||
var weekend = ScheduleRecurrence.WeeklyAt([DayOfWeek.Saturday, DayOfWeek.Sunday], new TimeOnly(3, 0));
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
Assert.Equal(DayOfWeek.Sunday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Sunday), ScheduleText.DayShort(DayOfWeek.Saturday)),
|
||||
ScheduleText.Days(weekend.Days));
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.When.Weekly", ScheduleText.Days(weekend.Days), ScheduleText.Time(new TimeOnly(3, 0))), ScheduleText.When(weekend));
|
||||
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||||
Assert.Equal(DayOfWeek.Monday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Saturday), ScheduleText.DayShort(DayOfWeek.Sunday)),
|
||||
ScheduleText.Days(weekend.Days));
|
||||
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Monday), ScheduleText.DayShort(DayOfWeek.Thursday)),
|
||||
ScheduleText.Days([DayOfWeek.Thursday, DayOfWeek.Monday]));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The editor's dropdowns say their choices in the new language, and keep what was chosen.</summary>
|
||||
[Test]
|
||||
public async Task TheOpenEditorSaysItsChoicesInTheNewLanguage()
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
await using var fx = await ScheduleFixture.CreateAsync(context);
|
||||
using var vm = await fx.ViewModelAsync();
|
||||
vm.NewCommand.Execute(null);
|
||||
var editor = Assert.NotNull(vm.Editor);
|
||||
editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Verify);
|
||||
editor.SelectedUnit = editor.Units.Single(u => u.Value == RecurrenceUnit.Minutes);
|
||||
editor.SelectedPriority = editor.Priorities.Single(p => p.Value == JobPriority.Normal);
|
||||
Assert.Equal(("minutes", "Normal"), (editor.SelectedUnit.Label, editor.SelectedPriority.Label));
|
||||
var actions = editor.ActionOptions;
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||||
|
||||
Assert.SequenceEqual(Enum.GetValues<RecurrenceUnit>().Select(u => Loc.L("Jobs.Editor.Unit." + u)), editor.Units.Select(u => u.Label));
|
||||
Assert.SequenceEqual(["In background", "Normale", "Alta"], editor.Priorities.Select(p => p.Label));
|
||||
Assert.Equal((RecurrenceUnit.Minutes, "minuti"), (editor.SelectedUnit.Value, editor.SelectedUnit.Label));
|
||||
Assert.Equal((JobPriority.Normal, "Normale"), (editor.SelectedPriority.Value, editor.SelectedPriority.Label));
|
||||
Assert.True(editor.Units.Any(u => ReferenceEquals(u, editor.SelectedUnit)) && editor.Priorities.Any(p => ReferenceEquals(p, editor.SelectedPriority)),
|
||||
"the choices are among the new options");
|
||||
|
||||
// The actions are new options too, so their dropdown reads their names again.
|
||||
Assert.False(ReferenceEquals(actions, editor.ActionOptions), "the action list was built again");
|
||||
Assert.Equal(("Scansione archivio", ScheduleActions.Verify), (editor.ActionOptions[0].Label, editor.SelectedAction.Name));
|
||||
Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the action is among the new options");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Chronos.App.Jobs;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Housekeeping;
|
||||
@@ -153,6 +155,97 @@ public sealed class SchedulesViewModelTests
|
||||
Assert.Equal(("Every 10 minutes", false), (scan.WhenText, scan.Schedule.CatchUp));
|
||||
}
|
||||
|
||||
/// <summary>A delete the index refuses (busy, locked) keeps the row: the schedule still runs, so it stays in sight.</summary>
|
||||
[Test]
|
||||
public async Task ADeleteThatFailsKeepsTheRow()
|
||||
{
|
||||
await using var fx = await ScheduleFixture.CreateAsync(_context);
|
||||
var toasts = new List<string>();
|
||||
using var vm = await fx.ViewModelAsync(toasts: toasts);
|
||||
await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Orphans", ScheduleActions.Orphans, new RecurrenceDto("monthly", Time: "05:00", DayOfMonth: 1)), null);
|
||||
var mine = vm.Rows.Single(r => !r.IsSystem);
|
||||
await using (var session = await fx.Db.Database.OpenAsync(_context.Cancellation))
|
||||
{
|
||||
await session.ExecuteScriptAsync("CREATE TRIGGER refuse_delete BEFORE DELETE ON schedules BEGIN SELECT RAISE(ABORT, 'the index is busy'); END;",
|
||||
_context.Cancellation);
|
||||
}
|
||||
|
||||
await vm.DeleteAsync(mine);
|
||||
Assert.SequenceEqual([Loc.L("Jobs.Schedule.Failed")], toasts);
|
||||
Assert.Count(4, vm.Rows);
|
||||
Assert.Contains(mine, vm.Rows);
|
||||
Assert.NotNull(await fx.Db.Schedules.GetAsync(mine.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether this PC runs an action is read again when Jobs › Scheduled is shown: proxies turned on in Settings › Archive
|
||||
/// make the Proxies schedule runnable and the action selectable, without a restart.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task ShowingTheTabReadsTheActionsAgain()
|
||||
{
|
||||
await using var fx = await ScheduleFixture.CreateAsync(_context);
|
||||
var archive = await fx.Archives.CreateAsync(Path.Combine(fx.Folder, "archive"), "archive", proxies: new ProxyPolicy { LongEdge = ProxyPolicy.Disabled });
|
||||
fx.Settings.LastArchivePath = archive.RootPath;
|
||||
using var vm = await fx.ViewModelAsync();
|
||||
Assert.Null((await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Proxies", ScheduleActions.Proxies, new RecurrenceDto("daily", Time: "01:00")), null)).Problem);
|
||||
var proxies = vm.Rows.Single(r => !r.IsSystem);
|
||||
Assert.False(vm.IsAvailable(ScheduleActions.Proxies));
|
||||
Assert.False(proxies.RunNowCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled"), proxies.RunNowToolTip);
|
||||
vm.NewCommand.Execute(null);
|
||||
var editor = Assert.NotNull(vm.Editor);
|
||||
Assert.False(editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies).IsAvailable);
|
||||
|
||||
await fx.Archives.UpdateSettingsAsync(archive.Id, a => a with { Proxies = a.Proxies with { LongEdge = 1920 } }, _context.Cancellation);
|
||||
await vm.RefreshActionsAsync();
|
||||
Assert.True(vm.IsAvailable(ScheduleActions.Proxies));
|
||||
Assert.True(proxies.RunNowCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Jobs.Schedule.RunNow"), proxies.RunNowToolTip);
|
||||
Assert.Equal(ScheduleText.ActionToolTip(ScheduleActions.Proxies), proxies.ActionToolTip);
|
||||
// The open editor follows too; what it had chosen stays chosen.
|
||||
var chosen = editor.SelectedAction.Name;
|
||||
Assert.True(editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies).IsAvailable);
|
||||
Assert.Equal(chosen, editor.SelectedAction.Name);
|
||||
Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the choice is one of the new options");
|
||||
editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies);
|
||||
Assert.Equal(ScheduleActions.Proxies, editor.SelectedAction.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The last result follows the newest news of the last job: a read of it that started before a live change (or before
|
||||
/// a later read) does not put back an older state.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task AReadOfTheLastJobNeverUndoesANewerChange()
|
||||
{
|
||||
await using var fx = await ScheduleFixture.CreateAsync(_context);
|
||||
using var vm = await fx.ViewModelAsync();
|
||||
var job = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Backup, State = JobState.Running };
|
||||
// A row of its own: the view model reads nothing into it meanwhile.
|
||||
var row = new ScheduleRowViewModel(vm.Rows[1].Schedule with { LastOutcome = ScheduleOutcome.Queued, LastJobId = job.Id }, vm);
|
||||
|
||||
// The job ends while it is read: the engine's Done comes first, the read's Running after it.
|
||||
var read = row.BeginLastJobRead();
|
||||
row.SetLastJob(job with { State = JobState.Done });
|
||||
row.SetLoadedLastJob(job, read);
|
||||
Assert.Equal(("done", StatusKind.Done), (row.LastText, row.LastKind));
|
||||
|
||||
// Two reads: the later one wins, whichever ends first.
|
||||
var first = row.BeginLastJobRead();
|
||||
var second = row.BeginLastJobRead();
|
||||
row.SetLoadedLastJob(job with { State = JobState.Failed }, second);
|
||||
row.SetLoadedLastJob(job, first);
|
||||
Assert.Equal(StatusKind.Failed, row.LastKind);
|
||||
|
||||
// A read of the job of the previous run does not apply once the schedule has run again.
|
||||
var stale = row.BeginLastJobRead();
|
||||
row.Update(row.Schedule with { LastJobId = Guid.CreateVersion7() });
|
||||
row.SetLoadedLastJob(job with { State = JobState.Done }, stale);
|
||||
Assert.Null(row.LastJob);
|
||||
Assert.Equal(("queued", StatusKind.Queued), (row.LastText, row.LastKind));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheEditorChecksEachFieldAndBuildsTheRecurrence()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user