feat(worker): allow cancelling a WaitingForChildren parent
Add WaitingForChildren to the CancelAsync guard so a parent waiting on its children can be cancelled. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -219,7 +219,8 @@ public sealed class TaskStateService : ITaskStateService
|
|||||||
var affected = await ctx.Tasks
|
var affected = await ctx.Tasks
|
||||||
.Where(t => t.Id == taskId &&
|
.Where(t => t.Id == taskId &&
|
||||||
(t.Status == TaskStatus.Running || t.Status == TaskStatus.Queued
|
(t.Status == TaskStatus.Running || t.Status == TaskStatus.Queued
|
||||||
|| t.Status == TaskStatus.WaitingForReview))
|
|| t.Status == TaskStatus.WaitingForReview
|
||||||
|
|| t.Status == TaskStatus.WaitingForChildren))
|
||||||
.ExecuteUpdateAsync(s => s
|
.ExecuteUpdateAsync(s => s
|
||||||
.SetProperty(t => t.Status, TaskStatus.Cancelled)
|
.SetProperty(t => t.Status, TaskStatus.Cancelled)
|
||||||
.SetProperty(t => t.FinishedAt, finishedAt), ct);
|
.SetProperty(t => t.FinishedAt, finishedAt), ct);
|
||||||
|
|||||||
@@ -162,6 +162,27 @@ public sealed class WaitingForChildrenLifecycleTests : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WaitingForChildren_parent_can_be_cancelled()
|
||||||
|
{
|
||||||
|
using (var ctx = _db.CreateContext())
|
||||||
|
{
|
||||||
|
ctx.Lists.Add(new ListEntity { Id = "l1", Name = "L", CreatedAt = DateTime.UtcNow });
|
||||||
|
ctx.Tasks.Add(new TaskEntity { Id = "par", ListId = "l1", Title = "Parent",
|
||||||
|
Status = TaskStatus.WaitingForChildren, CreatedAt = DateTime.UtcNow });
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _built.State.CancelAsync("par", DateTime.UtcNow, default);
|
||||||
|
|
||||||
|
Assert.True(result.Ok);
|
||||||
|
using (var ctx = _db.CreateContext())
|
||||||
|
{
|
||||||
|
var par = await new TaskRepository(ctx).GetByIdAsync("par");
|
||||||
|
Assert.Equal(TaskStatus.Cancelled, par!.Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ─── FinalizePlanningAsync ────────────────────────────────────────────
|
// ─── FinalizePlanningAsync ────────────────────────────────────────────
|
||||||
|
|
||||||
private async Task<string> SeedActivePlanningParentAsync(string id = "par")
|
private async Task<string> SeedActivePlanningParentAsync(string id = "par")
|
||||||
|
|||||||
Reference in New Issue
Block a user