PBI-50 F2-T1: claim-filter kind-based + lease_until persisten
Schema-sync vanaf Scrum4Me (PBI-50 F1): - PrStrategy.SPRINT_BATCH, ClaudeJobKind.SPRINT_IMPLEMENTATION - enum SprintTaskExecutionStatus, model SprintTaskExecution - ClaudeJob.lease_until + status_lease_until index - SprintRun.previous_run_id (self-relation) tryClaimJob in src/tools/wait-for-job.ts: - WHERE-clause refactor naar kind-based discriminatie. NULL-checks vervangen door expliciete `cj.kind IN (...)`. SPRINT_IMPLEMENTATION en TASK_IMPLEMENTATION vereisen beide actieve SprintRun (QUEUED/RUNNING). Idea-kinds blijven standalone claimable. - UPDATE op claim zet `lease_until = NOW() + INTERVAL '5 minutes'`. Tests: 19 wait-for-job tests groen. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7dbc9fe249
commit
de6bbd4edd
2 changed files with 118 additions and 62 deletions
|
|
@ -308,12 +308,15 @@ export async function tryClaimJob(
|
|||
): Promise<string | null> {
|
||||
// Atomic claim in a single transaction — also captures plan_snapshot from task.
|
||||
//
|
||||
// Sprint-flow filter (PBI-46):
|
||||
// Idea-jobs (task_id IS NULL) blijven onafhankelijk claimable.
|
||||
// Task-jobs zijn alleen claimable wanneer ze aan een actieve SprintRun
|
||||
// hangen (status QUEUED of RUNNING). Legacy task-jobs zonder sprint_run_id
|
||||
// en jobs in PAUSED/FAILED/CANCELLED/DONE SprintRuns worden overgeslagen.
|
||||
// PBI-50: claim-filter discrimineert via cj.kind:
|
||||
// - IDEA_GRILL/IDEA_MAKE_PLAN/PLAN_CHAT: standalone idea-jobs.
|
||||
// - TASK_IMPLEMENTATION/SPRINT_IMPLEMENTATION: alleen via actieve SprintRun
|
||||
// (status QUEUED of RUNNING). Legacy task-jobs zonder sprint_run_id en
|
||||
// jobs in PAUSED/FAILED/CANCELLED/DONE SprintRuns worden overgeslagen.
|
||||
// Bij eerste claim van een nog QUEUED SprintRun → status RUNNING.
|
||||
//
|
||||
// PBI-50 lease: lease_until = NOW() + 5min op claim. resetStaleClaimedJobs
|
||||
// reset bij verlopen lease.
|
||||
const rows = await prisma.$transaction(async (tx) => {
|
||||
const found = productId
|
||||
? await tx.$queryRaw<
|
||||
|
|
@ -327,8 +330,10 @@ export async function tryClaimJob(
|
|||
AND cj.product_id = ${productId}
|
||||
AND cj.status = 'QUEUED'
|
||||
AND (
|
||||
cj.task_id IS NULL
|
||||
OR (cj.sprint_run_id IS NOT NULL AND sr.status IN ('QUEUED', 'RUNNING'))
|
||||
cj.kind IN ('IDEA_GRILL', 'IDEA_MAKE_PLAN', 'PLAN_CHAT')
|
||||
OR (cj.kind IN ('TASK_IMPLEMENTATION', 'SPRINT_IMPLEMENTATION')
|
||||
AND cj.sprint_run_id IS NOT NULL
|
||||
AND sr.status IN ('QUEUED', 'RUNNING'))
|
||||
)
|
||||
ORDER BY cj.created_at ASC
|
||||
LIMIT 1
|
||||
|
|
@ -344,8 +349,10 @@ export async function tryClaimJob(
|
|||
WHERE cj.user_id = ${userId}
|
||||
AND cj.status = 'QUEUED'
|
||||
AND (
|
||||
cj.task_id IS NULL
|
||||
OR (cj.sprint_run_id IS NOT NULL AND sr.status IN ('QUEUED', 'RUNNING'))
|
||||
cj.kind IN ('IDEA_GRILL', 'IDEA_MAKE_PLAN', 'PLAN_CHAT')
|
||||
OR (cj.kind IN ('TASK_IMPLEMENTATION', 'SPRINT_IMPLEMENTATION')
|
||||
AND cj.sprint_run_id IS NOT NULL
|
||||
AND sr.status IN ('QUEUED', 'RUNNING'))
|
||||
)
|
||||
ORDER BY cj.created_at ASC
|
||||
LIMIT 1
|
||||
|
|
@ -362,7 +369,8 @@ export async function tryClaimJob(
|
|||
SET status = 'CLAIMED',
|
||||
claimed_by_token_id = ${tokenId},
|
||||
claimed_at = NOW(),
|
||||
plan_snapshot = ${snapshot}
|
||||
plan_snapshot = ${snapshot},
|
||||
lease_until = NOW() + INTERVAL '5 minutes'
|
||||
WHERE id = ${jobId}
|
||||
`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue