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
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user