E5: il cancello dei lavori lunghi cede il passo ai lavori di Alberto

La copia automatica prenderà il cancello con un permesso che cede
(TryEnterYielding): esclude gli altri lavori come ogni permesso, ma
importazione, ricostruzione e zip di fotogrammi lo prendono con
EnterAsync prima del proprio lucchetto e prima di registrare qualcosa.
Chi entra diventa subito titolare, la copia automatica riceve l'ordine
di fermarsi e si aspetta che lasci, in tempo reale, al più 15 secondi;
oltre, il lavoro è rifiutato con il messaggio della copia e la copia
resta titolare finché non lascia. «Cerca i video fermi» la ferma con
CancelYielding. BusyFirm decide i rifiuti anticipati, Busy resta per
chi aspetta (conversione della libreria, video fermi).

Una ricostruzione finita risveglia la copia automatica, e la sonda del
controllo delle cartelle è riservata come i file temporanei, così la
pulizia dei resti di un altro lavoro non la toglie mentre è in uso.

Risposta 49 di Alberto: la copia automatica cede sempre il passo.
Una riga in decisioni.md. ExportService resta alla tappa successiva.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-04 13:39:15 +01:00
1 parent f2568b5d88
commit cfd0ef88d7
11 files changed
+757 -58

No files matched your search

@@ -294,6 +294,35 @@ public sealed class StillVideoServiceTests
Assert.AreEqual(VideoAnalysisOutcome.Still, (await library.Db.VideoAnalyses.GetAsync(video.Sha256!, ct))!.Outcome);
}
[TestMethod]
public async Task AStartAsksAnAutomaticCopyToStopAndWaitsUntilItLetsGo()
{
var ct = TestContext.CancellationToken;
using var temp = new TempFolder();
await using var library = await TestLibrary.CreateAsync(temp);
var (account, video) = await SaveVideoAsync(library, "1", StillVideo(12));
var empty = await library.Db.Accounts.AddAsync(Make.Account("luca.demo", "200"));
var gate = new LongWorkGate();
var calls = new ConcurrentQueue<string>();
using var service = new StillVideoService(Environment(library, gate) with { Analyser = Counting(calls) });
Assert.IsTrue(gate.TryEnterYielding(LongWorkKind.Export, out var automatic, out var yield, out _));
// Nothing to search: the copy goes on.
Assert.IsFalse((await service.StartAsync(new ExportSelection.Account(empty.Id), ct)).Running);
Assert.IsFalse(yield.IsCancellationRequested);
// «Cerca i video fermi» comes first (§16 answer 49): the copy is asked to stop, and the job waits for the gate.
await service.StartAsync(new ExportSelection.Account(account.Id), ct);
Assert.IsTrue(yield.IsCancellationRequested);
await UntilAsync(() => service.Progress.Waiting == StillVideoText.LongWork, ct);
Assert.IsEmpty(calls);
automatic.Dispose();
await service.Job.WaitAsync(Patience, ct);
Assert.HasCount(1, calls);
Assert.AreEqual(VideoAnalysisOutcome.Still, (await library.Db.VideoAnalyses.GetAsync(video.Sha256!, ct))!.Outcome);
}
[TestMethod]
public async Task ASessionThatStartsDuringAnAnalysisMakesTheJobGiveWay()
{