Add atomic task deduplication with partial unique index

- Add partial unique index for active resource-scoped tasks
- Implement createTaskRunRecordAtomic for race-free task creation
- Update findOrEnqueueTask to use atomic insert first
- Add tests for concurrent task creation deduplication
This commit is contained in:
2026-03-15 14:40:38 -04:00
parent a7f7be50b4
commit ed4420b8db
5 changed files with 225 additions and 6 deletions

View File

@@ -0,0 +1,3 @@
CREATE UNIQUE INDEX IF NOT EXISTS `task_active_resource_uidx`
ON `task_run` (`user_id`, `task_type`, `resource_key`)
WHERE `resource_key` IS NOT NULL AND `status` IN ('queued', 'running');