feb1c7b3e9
Completes RenderPipeline2 phases 3-5. Additive throughout: with validation.enabled=false the pipeline behaves exactly as before. Validation (§8) runs on the worker straight after a render, while it still holds the job and the files are local. Everything is read from the EXR header — one 64 KB read per sampled frame, no pixel decode — so the engine needs no oiiotool. The render job deliberately stays open through the stage, so a worker that dies there is reaped and retried instead of stranding the export in VALIDATING. Timecode is the primary check and is anchored on the plate, never the API: measured on the live show, Shot.timecodeStart is the editorial in-point and sits one handle-length (8f) ahead of the plate, so checking against it would pass the defective exports and fail the correct ones. Reference precedence is manifest timing plate -> plate found on disk -> API value, and the API rank is WARN-only. The panel now resolves plate provenance by walking the comp's own footage layers, so the worker never guesses which element carries the comp's timing. Verified against real studio renders via the new --validate mode: it catches both defect classes seen in shipped work — the +8 handle offset and frame-derived timecode (00:00:41:17 = frame 1001 at 24fps). QC (§10) is one service behind two front doors, API-key for the panel and session for the web. PASS means ready to upload and nothing else; FAIL sets the comp task to CHANGES. The panel gains a QC section that imports the real EXR sequence at full res rather than the H.264. Delivery (§11) rides the existing queue as a DELIVERY_BUILD job: hard links with a copy fallback, verification by re-hashing delivered bytes against the validation-time digest, manifest.json and the CSV report. fsutil hardlink list is unavailable over SMB, so link identity is never queried — reading the bytes back covers links and copies alike. Also fixes ApiClient.ProgressAsync throwing on transport failure, which would have aborted work in flight during a brief server outage; progress reporting is best-effort by contract. Removes the stale RenderWorker/ rule from the root .gitignore. The worker's source is tracked like the rest of the repo and its own .gitignore already covers bin/, obj/ and publish/; the rule silently excluded new files while the existing 20 stayed tracked. Not yet applied: migration 20260813000000 was hand-written because the dev database was unavailable — run prisma migrate deploy and verify before relying on it. None of this has run against a live server. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
97 lines
3.6 KiB
C#
97 lines
3.6 KiB
C#
using System.Text.Json;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace VFXReviewWorker;
|
|
|
|
/// <summary>
|
|
/// Durable lifecycle reports (§7.6): fail/complete reports are written to the
|
|
/// spool directory before the first send attempt and replayed strictly in
|
|
/// order with exponential backoff (1 s → 60 s). Rendering continues during
|
|
/// server downtime; a report is deleted only once the server accepts it (or
|
|
/// permanently rejects it as contradictory).
|
|
///
|
|
/// Strict ordering is load-bearing beyond durability: the validation report
|
|
/// (E12) is only legal once complete-render (E11) has moved the Export to
|
|
/// VALIDATING, and in-order replay is what guarantees that, with no need for
|
|
/// the worker to wait on an ACK.
|
|
/// </summary>
|
|
public sealed class ReportSpooler
|
|
{
|
|
private readonly ApiClient _api;
|
|
private readonly ILogger<ReportSpooler> _log;
|
|
private readonly string _dir;
|
|
private readonly SemaphoreSlim _wake = new(0);
|
|
private long _seq;
|
|
|
|
public ReportSpooler(ApiClient api, ILogger<ReportSpooler> log, string? dir = null)
|
|
{
|
|
_api = api;
|
|
_log = log;
|
|
_dir = dir ?? WorkerOptions.SpoolDir;
|
|
Directory.CreateDirectory(_dir);
|
|
}
|
|
|
|
public void Enqueue(string kind, string jobId, Dictionary<string, object?> payload)
|
|
{
|
|
var report = new SpooledReport { Kind = kind, JobId = jobId, Payload = payload };
|
|
var name = $"{DateTimeOffset.UtcNow.UtcTicks:D20}_{Interlocked.Increment(ref _seq):D6}.json";
|
|
var tmp = Path.Combine(_dir, name + ".tmp");
|
|
var final = Path.Combine(_dir, name);
|
|
File.WriteAllText(tmp, JsonSerializer.Serialize(report, WorkerOptions.JsonOpts));
|
|
File.Move(tmp, final);
|
|
_wake.Release();
|
|
}
|
|
|
|
public bool HasPending => Directory.EnumerateFiles(_dir, "*.json").Any();
|
|
|
|
/// <summary>Long-running replay loop; started once by the worker service.</summary>
|
|
public async Task RunAsync(CancellationToken ct)
|
|
{
|
|
var backoff = TimeSpan.FromSeconds(1);
|
|
while (!ct.IsCancellationRequested)
|
|
{
|
|
var next = Directory.EnumerateFiles(_dir, "*.json").OrderBy(f => f, StringComparer.Ordinal).FirstOrDefault();
|
|
if (next is null)
|
|
{
|
|
try { await _wake.WaitAsync(TimeSpan.FromSeconds(5), ct); } catch (OperationCanceledException) { break; }
|
|
continue;
|
|
}
|
|
|
|
bool done;
|
|
try
|
|
{
|
|
var report = JsonSerializer.Deserialize<SpooledReport>(File.ReadAllText(next), WorkerOptions.JsonOpts);
|
|
if (report is null || string.IsNullOrEmpty(report.JobId))
|
|
{
|
|
_log.LogWarning("Discarding unreadable spool file {File}", next);
|
|
done = true;
|
|
}
|
|
else
|
|
{
|
|
done = await _api.SendLifecycleAsync(report.Kind, report.JobId, report.Payload, ct);
|
|
}
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
break;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_log.LogWarning(ex, "Spool replay attempt failed for {File}", next);
|
|
done = false;
|
|
}
|
|
|
|
if (done)
|
|
{
|
|
try { File.Delete(next); } catch { /* re-sent next pass; server side is idempotent */ }
|
|
backoff = TimeSpan.FromSeconds(1);
|
|
}
|
|
else
|
|
{
|
|
try { await Task.Delay(backoff, ct); } catch (OperationCanceledException) { break; }
|
|
backoff = TimeSpan.FromSeconds(Math.Min(backoff.TotalSeconds * 2, 60));
|
|
}
|
|
}
|
|
}
|
|
}
|