Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/constants/tasks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { subtaskTemplateBatchSize } from '@/constants/tasks'
import { runInBatches } from '@/utils/array'

describe('task constants', () => {
it('keeps subtask template fan-out within the production Prisma pool', async () => {
expect(subtaskTemplateBatchSize).toBe(1)

const state = { active: 0, max: 0 }

await runInBatches([1, 2, 3], subtaskTemplateBatchSize, async () => {
state.active += 1
state.max = Math.max(state.max, state.active)
await new Promise((resolve) => setTimeout(resolve, 1))
state.active -= 1
})

expect(state.max).toBe(1)
})
})
6 changes: 3 additions & 3 deletions src/constants/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const maxSubTaskDepth = 1

// Bounds how many subtasks we create concurrently when applying a template, so a
// template with many sub-templates can't exhaust the DB connection pool.
export const subtaskTemplateBatchSize = 5
// Production Prisma pool limit is 2; each subtask creation performs multiple DB
// writes, so keep template application serial within a single request.
export const subtaskTemplateBatchSize = 1
Loading