refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,545 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Jobs;
|
||||
using Chronos.App.Library;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Sections;
|
||||
|
||||
/// <summary>A filter chip of the Jobs toolbar ("Running · 4").</summary>
|
||||
public sealed class JobFilterChip(JobFilter filter, Action<JobFilter> select) : ObservableObject
|
||||
{
|
||||
private int _count;
|
||||
private bool _isSelected;
|
||||
|
||||
public JobFilter Filter { get; } = filter;
|
||||
|
||||
public string Text => Loc.L("Jobs.Filter." + Filter, Formatting.Count(_count));
|
||||
|
||||
public string ToolTip => Loc.L("Tooltips.Jobs.Filter." + Filter);
|
||||
|
||||
public ICommand SelectCommand { get; } = new RelayCommand(() => select(filter));
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set => Set(ref _isSelected, value);
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => _count;
|
||||
set
|
||||
{
|
||||
if (Set(ref _count, value)) OnPropertyChanged(nameof(Text));
|
||||
}
|
||||
}
|
||||
|
||||
internal void Refresh() => OnAllPropertiesChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jobs (BRIEF §12.6, Jobs.html): queue and history with live progress from the engine (batched to about 10
|
||||
/// updates a second), filters, queue order, an expandable log tail per job, and the row actions. Also feeds the
|
||||
/// shell's job bar, the status strip and the rail badge (running jobs, and failures not seen on this screen yet), and
|
||||
/// raises the toast of a long operation that ends (<see cref="JobNotices"/>), whichever screen started it.
|
||||
/// </summary>
|
||||
public sealed class JobsViewModel : SectionViewModel
|
||||
{
|
||||
private static readonly TimeSpan FlushInterval = TimeSpan.FromMilliseconds(100);
|
||||
private const int PageSize = 200;
|
||||
|
||||
private readonly JobListModel _model = new();
|
||||
private readonly JobUpdateBuffer _buffer = new();
|
||||
private readonly Dictionary<Guid, JobRowViewModel> _rows = [];
|
||||
private readonly HashSet<Guid> _unseenFailures = [];
|
||||
private readonly JobEndings _endings = new();
|
||||
|
||||
/// <summary>Finished renders whose toast was taken (<see cref="ClaimRenderToast"/>).</summary>
|
||||
private readonly HashSet<Guid> _renderToasts = [];
|
||||
|
||||
private readonly JobActions _actions;
|
||||
private CoalescingThrottle? _throttle;
|
||||
private IJobQueue? _queue;
|
||||
private JobFilter _filter = JobFilter.All;
|
||||
private string _searchText = string.Empty;
|
||||
private string? _cursor;
|
||||
private bool _hasMore;
|
||||
private bool _loading;
|
||||
private bool _hasLoaded;
|
||||
|
||||
public JobsViewModel(ShellViewModel shell)
|
||||
: base(SectionKey.Jobs, "Icon.Jobs")
|
||||
{
|
||||
Shell = shell;
|
||||
_actions = new JobActions(this);
|
||||
Chips = [.. Enum.GetValues<JobFilter>().Select(f => new JobFilterChip(f, SelectFilter) { IsSelected = f == JobFilter.All })];
|
||||
PauseCurrentCommand = new AsyncRelayCommand(PauseCurrentAsync, () => _model.Current is not null);
|
||||
PauseAllCommand = new AsyncRelayCommand(PauseAllAsync, () => _model.RunningCount > 0);
|
||||
ClearDoneCommand = new RelayCommand(ClearDone, () => _model.CountOf(JobFilter.Done, ClearedAt) + _model.CountOf(JobFilter.Failed, ClearedAt) > 0);
|
||||
RenderingSettingsCommand = new RelayCommand(() =>
|
||||
{
|
||||
Shell.Settings.Page = SettingsPage.Rendering;
|
||||
Shell.Navigate(SectionKey.Settings);
|
||||
});
|
||||
LoadMoreCommand = new RelayCommand(() => _ = LoadMoreAsync());
|
||||
ImportCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Import));
|
||||
}
|
||||
|
||||
public ShellViewModel Shell { get; }
|
||||
|
||||
/// <summary>Rows in display order for the current filter and search.</summary>
|
||||
public ObservableCollection<JobRowViewModel> Rows { get; } = [];
|
||||
|
||||
public IReadOnlyList<JobFilterChip> Chips { get; }
|
||||
|
||||
public ICommand PauseCurrentCommand { get; }
|
||||
public ICommand PauseAllCommand { get; }
|
||||
public ICommand ClearDoneCommand { get; }
|
||||
public ICommand RenderingSettingsCommand { get; }
|
||||
public ICommand LoadMoreCommand { get; }
|
||||
|
||||
/// <summary>The empty state's one action: jobs start with an import.</summary>
|
||||
public ICommand ImportCommand { get; }
|
||||
|
||||
public JobFilter Filter
|
||||
{
|
||||
get => _filter;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _filter, value)) return;
|
||||
foreach (var chip in Chips) chip.IsSelected = chip.Filter == value;
|
||||
SyncRows();
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchText
|
||||
{
|
||||
get => _searchText;
|
||||
set
|
||||
{
|
||||
if (Set(ref _searchText, value ?? string.Empty)) SyncRows();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"8 photos at once": what the running job of this PC processes together (Settings › Rendering › Parallelism).</summary>
|
||||
public string ParallelismText => Loc.Plural("Jobs.Parallelism", Shell.Services.Parallelism);
|
||||
|
||||
/// <summary>The engine of this PC runs jobs (it runs none before it starts).</summary>
|
||||
public bool HasEngine => _queue is { IsRunning: true };
|
||||
|
||||
/// <summary>The priority queue of Settings › Rendering is on: higher jobs pause the running one.</summary>
|
||||
public bool IsPriorityQueueOn => HasEngine && Shell.Services.Settings.PriorityQueue;
|
||||
|
||||
/// <summary>"History keeps 90 days".</summary>
|
||||
public string HistoryText => Loc.Plural("Jobs.History", (long)new JobEngineOptions().HistoryRetention.TotalDays);
|
||||
|
||||
public bool IsEmpty => _hasLoaded && Rows.Count == 0;
|
||||
|
||||
public bool HasRows => Rows.Count > 0;
|
||||
|
||||
internal IJobQueue? Queue => _queue;
|
||||
|
||||
internal JobListModel Model => _model;
|
||||
|
||||
private DateTimeOffset? ClearedAt => Shell.Services.Settings.JobsClearedAt;
|
||||
|
||||
/// <summary>Subscribes to the engine and loads the first page of jobs.</summary>
|
||||
public void Attach()
|
||||
{
|
||||
_queue = Shell.Services.Jobs;
|
||||
if (_queue is null)
|
||||
{
|
||||
_hasLoaded = true;
|
||||
RaiseState();
|
||||
return;
|
||||
}
|
||||
_throttle = new CoalescingThrottle(FlushInterval, SynchronizationContext.Current, Flush);
|
||||
_queue.JobChanged += OnJobChanged;
|
||||
_queue.Progress += OnProgress;
|
||||
_ = LoadMoreAsync();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_queue is not null)
|
||||
{
|
||||
_queue.JobChanged -= OnJobChanged;
|
||||
_queue.Progress -= OnProgress;
|
||||
}
|
||||
_throttle?.Dispose();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>The UI language changed: the rows, the filter chips and the job bar say it again in the new language.</summary>
|
||||
protected override void OnLanguageChanged()
|
||||
{
|
||||
foreach (var row in _rows.Values) row.Refresh();
|
||||
foreach (var chip in Chips) chip.Refresh();
|
||||
UpdateShell();
|
||||
base.OnLanguageChanged();
|
||||
}
|
||||
|
||||
/// <summary>Reads the job list again from the first page (after jobs were written outside the engine).</summary>
|
||||
public Task ReloadAsync()
|
||||
{
|
||||
_cursor = null;
|
||||
_hasMore = true;
|
||||
_hasLoaded = false;
|
||||
return LoadMoreAsync();
|
||||
}
|
||||
|
||||
/// <summary>Next page of the history (newest first); the view calls it when the list scrolls near its end.</summary>
|
||||
public async Task LoadMoreAsync()
|
||||
{
|
||||
if (_queue is null || _loading || (_hasLoaded && !_hasMore)) return;
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
var stamp = _model.Stamp;
|
||||
var page = await _queue.ListAsync(_cursor, PageSize);
|
||||
foreach (var job in page.Items) _model.ApplyLoaded(job, stamp);
|
||||
_cursor = page.NextCursor;
|
||||
_hasMore = page.NextCursor is not null;
|
||||
}
|
||||
catch (DatabaseException ex)
|
||||
{
|
||||
Log.Warning("jobs", "Job list unavailable", ex);
|
||||
_hasMore = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_loading = false;
|
||||
_hasLoaded = true;
|
||||
}
|
||||
Flush();
|
||||
}
|
||||
|
||||
/// <summary>Applies everything buffered since the last flush (UI thread).</summary>
|
||||
internal void Flush()
|
||||
{
|
||||
var (jobs, progress) = _buffer.Drain();
|
||||
foreach (var job in jobs)
|
||||
{
|
||||
var before = _model[job.Id]?.State;
|
||||
_model.Apply(job);
|
||||
Follow(before, job);
|
||||
}
|
||||
foreach (var p in progress) _model.Apply(p);
|
||||
foreach (var ending in _endings.Take(_model.IsBusy)) Shell.ShowToast(ToastFor(ending));
|
||||
SyncRows();
|
||||
UpdateShell();
|
||||
}
|
||||
|
||||
/// <summary>Failures seen on this screen no longer count on the rail.</summary>
|
||||
protected override void OnActivated()
|
||||
{
|
||||
if (_unseenFailures.Count == 0) return;
|
||||
_unseenFailures.Clear();
|
||||
UpdateShell();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A change the engine reported (these are live, never pages read again): a failure counts on the rail until this
|
||||
/// screen is opened, and a long operation that ends is announced at the end of the flush (<see cref="JobEndings"/>).
|
||||
/// </summary>
|
||||
private void Follow(JobState? before, Job job)
|
||||
{
|
||||
if (job.State != JobState.Failed) _unseenFailures.Remove(job.Id);
|
||||
else if (before != JobState.Failed && !IsSelected) _unseenFailures.Add(job.Id);
|
||||
var notice = JobNotices.For(before, job);
|
||||
// A flush can take the end before the editor that follows the render has seen it: the editor says it, with its output.
|
||||
if (notice == JobNotice.Done && job.Kind == JobKind.Render
|
||||
&& (Shell.Sequence.Editor?.FollowsRender(job.Id) == true || !ClaimRenderToast(job.Id))) return;
|
||||
_endings.Add(notice, job);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes the toast of a finished render, which is said once (UI thread): true for the first caller only, which then
|
||||
/// raises it. The editor of the render's sequence takes it when it sees the render end, and says it with the output
|
||||
/// file even when the sequence cannot be read again or the editor closed meanwhile; a render the editor did not
|
||||
/// follow is said here.
|
||||
/// </summary>
|
||||
internal bool ClaimRenderToast(Guid jobId) => _renderToasts.Add(jobId);
|
||||
|
||||
/// <summary>
|
||||
/// The toast of a job that ended, with one action (BRIEF §12.1, §0.2 rule 6). Several endings at once (a batch
|
||||
/// finished, or failed together) say how many and lead to this screen. Clicking the Windows notification of a
|
||||
/// toast opens what it names; a retry waits until the user has seen why the job failed.
|
||||
/// </summary>
|
||||
private Toast ToastFor(JobEnding ending)
|
||||
{
|
||||
var job = ending.Jobs[0];
|
||||
var failed = ending.Notice == JobNotice.Failed;
|
||||
if (ending.Jobs.Count > 1)
|
||||
{
|
||||
return new Toast
|
||||
{
|
||||
Title = Loc.Plural(failed ? "Shell.Job.FailedPlural" : "Shell.Job.DonePlural", ending.Jobs.Count),
|
||||
Message = ending.Jobs.All(j => j.Kind == job.Kind) ? JobText.Kind(job.Kind) : null,
|
||||
ActionText = Loc.L("Shell.Nav.Jobs"),
|
||||
ActionToolTip = Loc.L("Tooltips.Nav.Jobs"),
|
||||
ActionCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Jobs)),
|
||||
IsError = failed,
|
||||
RunsFromNotification = true,
|
||||
};
|
||||
}
|
||||
if (!failed)
|
||||
{
|
||||
return new Toast
|
||||
{
|
||||
Title = Loc.L("Shell.Job.Done"),
|
||||
Message = JobText.Name(job),
|
||||
ActionText = Loc.L("Jobs.Action.Open"),
|
||||
ActionToolTip = Loc.L("Tooltips.Jobs.Open"),
|
||||
ActionCommand = new AsyncRelayCommand(() => OpenTargetAsync(job)),
|
||||
RunsFromNotification = true,
|
||||
};
|
||||
}
|
||||
return job.Kind == JobKind.Import
|
||||
// The Import screen resumes an import with its plan and card; it holds the retry.
|
||||
? new Toast
|
||||
{
|
||||
Title = Loc.L("Shell.Job.Failed"),
|
||||
Message = JobText.Name(job),
|
||||
ActionText = Loc.L("Shell.Nav.Import"),
|
||||
ActionToolTip = Loc.L("Tooltips.Nav.Import"),
|
||||
ActionCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Import)),
|
||||
IsError = true,
|
||||
RunsFromNotification = true,
|
||||
}
|
||||
: new Toast
|
||||
{
|
||||
Title = Loc.L("Shell.Job.Failed"),
|
||||
Message = JobText.Name(job),
|
||||
ActionText = Loc.L("Jobs.Action.Retry"),
|
||||
ActionToolTip = Loc.L("Tooltips.Jobs.Retry"),
|
||||
ActionCommand = new AsyncRelayCommand(() => _queue?.ResumeAsync(job.Id) ?? Task.CompletedTask),
|
||||
IsError = true,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>A job changed state (any thread; tests feed it too): buffered until the next flush.</summary>
|
||||
internal void OnJobChanged(Job job)
|
||||
{
|
||||
_buffer.Post(job);
|
||||
_throttle?.Signal();
|
||||
}
|
||||
|
||||
private void OnProgress(JobProgressInfo progress)
|
||||
{
|
||||
_buffer.Post(progress);
|
||||
_throttle?.Signal();
|
||||
}
|
||||
|
||||
private void SelectFilter(JobFilter filter) => Filter = filter;
|
||||
|
||||
/// <summary>Brings <see cref="Rows"/> to the model's order with moves (rows keep their expanded log).</summary>
|
||||
private void SyncRows()
|
||||
{
|
||||
_model.PriorityQueue = Shell.Services.PriorityQueue;
|
||||
var ordered = _model.Ordered(_filter, _searchText, ClearedAt);
|
||||
var wanted = new HashSet<Guid>(ordered.Select(e => e.Id));
|
||||
for (var i = Rows.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!wanted.Contains(Rows[i].Id)) Rows.RemoveAt(i);
|
||||
}
|
||||
for (var i = 0; i < ordered.Count; i++)
|
||||
{
|
||||
var entry = ordered[i];
|
||||
var position = entry.State == JobState.Queued ? _model.QueuePosition(entry.Id) : 0;
|
||||
if (!_rows.TryGetValue(entry.Id, out var row))
|
||||
{
|
||||
row = new JobRowViewModel(entry, position, _actions);
|
||||
_rows[entry.Id] = row;
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Update(entry, position);
|
||||
}
|
||||
if (i < Rows.Count && ReferenceEquals(Rows[i], row)) continue;
|
||||
var existing = Rows.IndexOf(row);
|
||||
if (existing >= 0) Rows.Move(existing, i);
|
||||
else Rows.Insert(i, row);
|
||||
}
|
||||
foreach (var chip in Chips) chip.Count = _model.CountOf(chip.Filter, ClearedAt);
|
||||
RaiseState();
|
||||
}
|
||||
|
||||
private void UpdateShell()
|
||||
{
|
||||
if (_model.Current is { } current)
|
||||
Shell.SetJob(JobText.Bar(current), current.Fraction ?? 0, indeterminate: current.Fraction is null, name: JobText.Name(current.Job));
|
||||
else
|
||||
Shell.SetJob(null, 0);
|
||||
// The status strip and the Running chip count the same jobs: running or paused (Jobs.html). The rail badge adds the
|
||||
// failures not seen here yet, which also turn the taskbar button red while no job runs.
|
||||
var active = _model.CountOf(JobFilter.Running);
|
||||
Shell.SetJobCount(active, _model.QueuedCount);
|
||||
Shell.SetUnseenFailures(_unseenFailures.Count);
|
||||
Badge = active + _unseenFailures.Count;
|
||||
OnPropertyChanged(nameof(ParallelismText));
|
||||
OnPropertyChanged(nameof(HasEngine));
|
||||
OnPropertyChanged(nameof(IsPriorityQueueOn));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
private void RaiseState()
|
||||
{
|
||||
OnPropertyChanged(nameof(IsEmpty));
|
||||
OnPropertyChanged(nameof(HasRows));
|
||||
}
|
||||
|
||||
private async Task PauseCurrentAsync()
|
||||
{
|
||||
if (_model.Current is { } current && _queue is not null) await _queue.PauseAsync(current.Id);
|
||||
}
|
||||
|
||||
private async Task PauseAllAsync()
|
||||
{
|
||||
if (_queue is null) return;
|
||||
foreach (var entry in _model.Ordered(JobFilter.Running).Where(e => e.State == JobState.Running).ToList()) await _queue.PauseAsync(entry.Id);
|
||||
}
|
||||
|
||||
private void ClearDone()
|
||||
{
|
||||
Shell.Services.Settings.JobsClearedAt = DateTimeOffset.UtcNow;
|
||||
Shell.Services.SaveSettings();
|
||||
SyncRows();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens what a job worked on inside Chronos: its sequence in the editor; several sequences (a deep analysis of a
|
||||
/// Library selection) in the Library, every one of them selected; else the Archive screen. A job over more sequences
|
||||
/// than a Library page holds (a maintenance run over a whole archive) opens the Library as it is: looking each one
|
||||
/// up, then reading page after page to select them all, would hold the screen.
|
||||
/// </summary>
|
||||
internal async Task OpenTargetAsync(Job job)
|
||||
{
|
||||
var db = Shell.Services.Database;
|
||||
if (db is null || job.TargetIds.Count == 0) return;
|
||||
var targets = job.TargetIds.Distinct().ToList();
|
||||
if (targets.Count > LibraryPager.DefaultPageSize)
|
||||
{
|
||||
Shell.Navigate(SectionKey.Library);
|
||||
return;
|
||||
}
|
||||
// Each one is looked up: an id no longer in the index would have the Library read every page in search of it.
|
||||
var sequences = new List<Guid>(targets.Count);
|
||||
foreach (var id in targets)
|
||||
{
|
||||
if (await db.Sequences.GetAsync(id) is { } sequence) sequences.Add(sequence.Id);
|
||||
}
|
||||
switch (sequences.Count)
|
||||
{
|
||||
case 0:
|
||||
Shell.Navigate(SectionKey.Archive);
|
||||
break;
|
||||
case 1:
|
||||
Shell.OpenSequence(sequences[0]);
|
||||
break;
|
||||
default:
|
||||
Shell.Navigate(SectionKey.Library);
|
||||
await Shell.Library.ShowSelectedAsync(sequences);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Shows the folder of what a job worked on in Explorer.</summary>
|
||||
internal async Task RevealTargetAsync(Job job)
|
||||
{
|
||||
var db = Shell.Services.Database;
|
||||
if (db is null || job.TargetIds.Count == 0) return;
|
||||
var id = job.TargetIds[0];
|
||||
if (await db.Sequences.GetAsync(id) is { } sequence && await db.Archives.GetAsync(sequence.ArchiveId) is { } owner)
|
||||
ShellActions.Reveal(Path.Combine(owner.RootPath, sequence.Folder.Replace('/', Path.DirectorySeparatorChar)));
|
||||
else if (await db.Archives.GetAsync(id) is { } archive)
|
||||
ShellActions.Reveal(archive.RootPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Row actions per job state (Jobs.html) and their commands.</summary>
|
||||
internal sealed class JobActions(JobsViewModel owner)
|
||||
{
|
||||
public string WorkerId => owner.Queue?.WorkerId ?? Environment.MachineName;
|
||||
|
||||
public IReadOnlyList<JobAction> For(JobEntry entry)
|
||||
{
|
||||
var job = entry.Job;
|
||||
var row = JobText.Name(job);
|
||||
return entry.State switch
|
||||
{
|
||||
JobState.Running =>
|
||||
[
|
||||
OnQueue("Jobs.Action.Pause", "Tooltips.Jobs.Pause", row, q => q.PauseAsync(job.Id)),
|
||||
OnQueue("Jobs.Action.Cancel", "Tooltips.Jobs.Cancel", row, q => q.CancelAsync(job.Id)),
|
||||
],
|
||||
JobState.Paused =>
|
||||
[
|
||||
OnQueue("Jobs.Action.Resume", "Tooltips.Jobs.Resume", row, q => q.ResumeAsync(job.Id)),
|
||||
OnQueue("Jobs.Action.Cancel", "Tooltips.Jobs.Cancel", row, q => q.CancelAsync(job.Id)),
|
||||
],
|
||||
JobState.Queued when job.Priority < JobPriority.User =>
|
||||
[
|
||||
OnQueue("Jobs.Action.MoveUp", "Tooltips.Jobs.MoveUp", row, q => q.RaisePriorityAsync(job.Id)),
|
||||
OnQueue("Jobs.Action.Remove", "Tooltips.Jobs.Remove", row, q => q.CancelAsync(job.Id)),
|
||||
],
|
||||
JobState.Queued =>
|
||||
[
|
||||
OnQueue("Jobs.Action.Pause", "Tooltips.Jobs.PauseQueued", row, q => q.PauseAsync(job.Id)),
|
||||
OnQueue("Jobs.Action.Remove", "Tooltips.Jobs.Remove", row, q => q.CancelAsync(job.Id)),
|
||||
],
|
||||
JobState.Failed =>
|
||||
[
|
||||
OnQueue("Jobs.Action.Retry", "Tooltips.Jobs.Retry", row, q => q.ResumeAsync(job.Id)),
|
||||
Action("Jobs.Action.Show", "Tooltips.Jobs.Show", row, () => owner.OpenTargetAsync(job)),
|
||||
],
|
||||
JobState.Cancelled =>
|
||||
[
|
||||
OnQueue("Jobs.Action.Retry", "Tooltips.Jobs.Retry", row, q => q.ResumeAsync(job.Id)),
|
||||
],
|
||||
_ =>
|
||||
[
|
||||
Action("Jobs.Action.Open", "Tooltips.Jobs.Open", row, () => owner.OpenTargetAsync(job)),
|
||||
Action("Jobs.Action.Folder", "Tooltips.Jobs.Folder", row, () => owner.RevealTargetAsync(job)),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Reads the stored log tail of a row (persisted with each checkpoint).</summary>
|
||||
public async Task LoadLogAsync(JobRowViewModel row)
|
||||
{
|
||||
if (owner.Queue is not { } queue) return;
|
||||
try
|
||||
{
|
||||
if (await queue.GetAsync(row.Id) is { } job) row.SetLog(job.LogTail);
|
||||
}
|
||||
catch (DatabaseException ex)
|
||||
{
|
||||
Log.Warning("jobs", "Job log unavailable", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A row button named with its row for screen readers ("Pause: Render · Harbour sunset").</summary>
|
||||
private static JobAction Action(string textKey, string toolTipKey, string row, Func<Task> run)
|
||||
{
|
||||
var text = Loc.L(textKey);
|
||||
return new JobAction(text, Loc.L(toolTipKey), Loc.L("Jobs.ActionFor", text, row), new AsyncRelayCommand(run));
|
||||
}
|
||||
|
||||
private JobAction OnQueue(string textKey, string toolTipKey, string row, Func<IJobQueue, Task> run) =>
|
||||
Action(textKey, toolTipKey, row, async () =>
|
||||
{
|
||||
if (owner.Queue is { } queue) await run(queue);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user