namespace VFXReviewWorker; /// /// Renews a job's lease with progress reports while the worker does something /// long that reports nothing on its own — the High quality encode and the /// ProRes upload can each outlast a 300 s lease, and an expired lease lets the /// reaper hand the job to another machine mid-upload. /// internal sealed class LeaseKeepAlive : IAsyncDisposable { private readonly CancellationTokenSource _cts; private readonly Task _loop; public LeaseKeepAlive(ApiClient api, string jobId, string machineId, TimeSpan interval, CancellationToken shutdown) { _cts = CancellationTokenSource.CreateLinkedTokenSource(shutdown); var token = _cts.Token; _loop = Task.Run(async () => { try { while (!token.IsCancellationRequested) { await Task.Delay(interval, token); // Best-effort by contract (ApiClient.ProgressAsync never throws // on transport errors); progress stays at 1.0 — the render is done. await api.ProgressAsync(jobId, machineId, 1.0, null, null, null, null, token); } } catch (OperationCanceledException) { // stopped } }); } public async ValueTask DisposeAsync() { _cts.Cancel(); try { await _loop; } catch { /* already reported */ } _cts.Dispose(); } }