fix(jobs): claim only handled kinds and requeue numbered workers after a crash
An engine with no handlers (or a filter it could not serve) claimed every job, so a host without a render handler would fail render-node work. With several workers, jobs carry node ids such as pc#1, but crash recovery only matched the bare node id and left them running forever. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+52
-5
No files matched your search
@@ -120,6 +120,45 @@ public sealed class JobEngineTests(TestContext context)
|
||||
Assert.Equal("7", handler.SeenCheckpoints.Single());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task JobsOfNumberedWorkersResumeAfterRestart()
|
||||
{
|
||||
await using var db = await OpenAsync();
|
||||
var job = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Thumbs, State = JobState.Queued, Created = DateTimeOffset.UtcNow };
|
||||
await db.Jobs.EnqueueAsync(job);
|
||||
Assert.NotNull(await db.Jobs.ClaimNextAsync("pc#1"));
|
||||
var other = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Thumbs, State = JobState.Queued, Created = DateTimeOffset.UtcNow };
|
||||
await db.Jobs.EnqueueAsync(other);
|
||||
Assert.NotNull(await db.Jobs.ClaimNextAsync("pc2#0"));
|
||||
// Restarting node "pc" (two workers: pc#0, pc#1) requeues pc#1's job, never another node's.
|
||||
var handler = new CountingHandler(JobKind.Thumbs, 3);
|
||||
await using var engine = new JobEngine(db, [handler], new JobEngineOptions { Workers = 2, WorkerId = "pc" });
|
||||
await engine.StartAsync();
|
||||
await WaitForStateAsync(db, job.Id, JobState.Done, TimeSpan.FromSeconds(10));
|
||||
Assert.Equal(JobState.Running, (await db.Jobs.GetAsync(other.Id))!.State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyKindsWithAHandlerAreClaimed()
|
||||
{
|
||||
await using var db = await OpenAsync();
|
||||
await using (var idle = new JobEngine(db, [], new JobEngineOptions { Workers = 1, WorkerId = "idle" }))
|
||||
{
|
||||
await idle.StartAsync();
|
||||
var render = await idle.EnqueueAsync(JobKind.Render, []);
|
||||
await Task.Delay(300);
|
||||
Assert.Equal(JobState.Queued, (await db.Jobs.GetAsync(render.Id))!.State);
|
||||
}
|
||||
var handler = new CountingHandler(JobKind.Thumbs, 1);
|
||||
await using var engine = new JobEngine(db, [handler], new JobEngineOptions { Workers = 1, WorkerId = "t", Kinds = [JobKind.Thumbs, JobKind.Render] });
|
||||
await engine.StartAsync();
|
||||
var thumbs = await engine.EnqueueAsync(JobKind.Thumbs, []);
|
||||
await WaitForStateAsync(db, thumbs.Id, JobState.Done, TimeSpan.FromSeconds(10));
|
||||
var pending = (await db.Jobs.ListAsync(JobState.Queued)).Items;
|
||||
Assert.Count(1, pending);
|
||||
Assert.Equal(JobKind.Render, pending[0].Kind);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HandlerFailureMarksJobFailedWithMessage()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user