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
@@ -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