A running job now says what it does now: "Verifying photo 812 of 2,400 · Harbour sunset · sequence 3 of 41". A paused or failed job says where it stopped. The line appears in the Jobs table under the target, in the job bar (at most 60 characters, the item dropped first, the bar text also its tooltip), in the Archive's recent maintenance (refreshed at most twice a second), in the editor's server-job line and in the sync tooltip. Byte jobs now count sizes in the bar. While connected, the Server section lists the server's running and paused jobs, live through the jobs API and the jobProgress events. Pause, Resume and Cancel are offered only to an account that manages the archive, which is what the server requires to act on someone else's job; for any other account the list is read-only. The list hides while nothing runs, and the capture gains a server-jobs scene. The admin panel's Jobs page and dashboard show the same line under the target and update it with every progress event. The steps, parts and sub-steps are in English and Italian, and an unknown step shows its counts only. Refs #65 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
3.6 KiB
C#
90 lines
3.6 KiB
C#
using System.Runtime.CompilerServices;
|
|
using Chronos.App.Server;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Protocol;
|
|
|
|
namespace Chronos.App.DesignTime;
|
|
|
|
/// <summary>
|
|
/// The sample server's jobs for the Server section's job list (owner review 5, #65), for the screenshots: empty until
|
|
/// <see cref="Fill"/>, then a verification and a thumbnail pass running with what each does now, and a proxy pass paused.
|
|
/// Pause, resume and cancel change the list; no event ever comes. Thread-safe; disposing it does nothing, so it can be reused.
|
|
/// </summary>
|
|
public sealed class SampleServerJobs : IServerJobsApi
|
|
{
|
|
private readonly Lock _gate = new();
|
|
private List<JobDto> _jobs = [];
|
|
|
|
/// <summary>The sample's running and paused jobs.</summary>
|
|
public void Fill()
|
|
{
|
|
var now = SampleData.Now;
|
|
lock (_gate)
|
|
{
|
|
_jobs =
|
|
[
|
|
Job(JobKind.Verify, "Harbour sunset", JobState.Running, 812, 2_400, 38.5, 41, now.AddMinutes(-6),
|
|
new JobDetail(JobStep.Verify, "Harbour sunset", 812, 2_400, 3, 41, JobPartUnit.Sequence)),
|
|
Job(JobKind.Thumbs, "Sunrise over Superga", JobState.Running, 1_240, 3_600, 52.0, 45, now.AddMinutes(-3),
|
|
new JobDetail(JobStep.Thumbs, "Sunrise over Superga", 1_240, 3_600, 2, 7, JobPartUnit.Sequence)),
|
|
Job(JobKind.Proxies, "Alpine lake, winter", JobState.Paused, 300, 1_800, null, null, now.AddMinutes(-40),
|
|
new JobDetail(JobStep.Proxies, "Alpine lake, winter", 300, 1_800, 1, 2, JobPartUnit.Sequence)),
|
|
];
|
|
}
|
|
}
|
|
|
|
/// <summary>Nothing runs on the server again.</summary>
|
|
public void Clear()
|
|
{
|
|
lock (_gate) _jobs = [];
|
|
}
|
|
|
|
public Task<Page<JobDto>> ListJobsAsync(string state, string? cursor, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
var items = _jobs.Where(j => j.State == state).ToList();
|
|
return Task.FromResult(new Page<JobDto>(items, null, items.Count));
|
|
}
|
|
}
|
|
|
|
public Task<JobDto> GetJobAsync(Guid id, CancellationToken cancellationToken)
|
|
{
|
|
lock (_gate) return Task.FromResult(_jobs.Single(j => j.Id == id));
|
|
}
|
|
|
|
public Task<JobDto> PauseJobAsync(Guid id, CancellationToken cancellationToken) => SetState(id, JobState.Paused);
|
|
|
|
public Task<JobDto> ResumeJobAsync(Guid id, CancellationToken cancellationToken) => SetState(id, JobState.Running);
|
|
|
|
public Task<JobDto> CancelJobAsync(Guid id, CancellationToken cancellationToken) => SetState(id, JobState.Cancelled);
|
|
|
|
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
|
{
|
|
await Task.Delay(Timeout.Infinite, cancellationToken).ConfigureAwait(false);
|
|
yield break;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
private Task<JobDto> SetState(Guid id, JobState state)
|
|
{
|
|
lock (_gate)
|
|
{
|
|
var index = _jobs.FindIndex(j => j.Id == id);
|
|
var job = _jobs[index] with { State = JobWire.State(state) };
|
|
if (state is JobState.Running or JobState.Paused) _jobs[index] = job;
|
|
else _jobs.RemoveAt(index);
|
|
return Task.FromResult(job);
|
|
}
|
|
}
|
|
|
|
private static JobDto Job(JobKind kind, string target, JobState state, long done, long total, double? rate, double? eta, DateTimeOffset started,
|
|
JobDetail detail) =>
|
|
new(Guid.NewGuid(), JobWire.Kind(kind), [Guid.NewGuid()], target, JobWire.State(state), JobWire.Priority(JobPriority.Background), done, total,
|
|
rate, eta, null, null, 1, null, started, started, null, null, JobWire.Detail(detail));
|
|
}
|