PrefectHQ
prefect
BlogDocsChangelog

Add task keys to docket calls in API handlers to prevent duplicate execution

#20210Merged
Comparing
add-docket-task-keys
(
4a4d2a1
) with
main
(
3d3ecf2
)
CodSpeed Performance Gauge
0%
Untouched
2
Ignored
6

Benchmarks

Passed

bench_task_decorator
benches/bench_tasks.py
CodSpeed Performance Gauge
+1%
608.5 µs602.7 µs
bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s

Ignored

bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+6%
12.1 ms11.5 ms
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
107.7 ms107.3 ms
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+10%
5.6 ms5.1 ms
bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+4%
34 ms32.6 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-4%
163.5 ms169.5 ms

Commits

Click on a commit to change the comparison range
Base
main
3d3ecf2
-0.18%
Add task keys to docket calls in API handlers to prevent duplicate execution When multiple API servers process the same request, docket tasks could be created and executed in parallel, causing database contention and potential deadlocks. This adds unique task keys to all docket.add() calls in API handlers so that only one task with a given key can be scheduled at a time. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
0c1e141
7 hours ago
by desertaxle
-0.06%
Merge branch 'main' into add-docket-task-keys
6c010c8
6 hours ago
by desertaxle
+0.08%
Add tests for docket task keys in API handlers Tests verify that API handlers use deterministic task keys when scheduling background docket tasks. The tests confirm: - Keys are based on relevant resource IDs (work queue, work pool, deployment, etc.) - Same request parameters produce identical keys (at-most-once semantics) - Deployment IDs are sorted to ensure order-independent keys Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d94a50f
6 hours ago
by desertaxle
+0.47%
Add integration tests for at-most-once execution with real Docket These tests verify the actual at-most-once execution behavior by using a real Docket instance and inspecting the task queue via docket.snapshot(). The tests confirm that: - Duplicate API requests only queue one task per unique key - Task keys are properly formed and present in the Docket queue - Deployment ID ordering doesn't affect task key generation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9a6a444
2 hours ago
by desertaxle
+0.03%
Remove mock-based tests, keep only real Docket integration tests The integration tests using a real Docket instance are more valuable as they verify the actual at-most-once execution behavior by inspecting the task queue. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
baf5a38
2 hours ago
by desertaxle
+0.15%
Fix ContextVar issue in test fixtures for Python 3.10 Use the existing `app` fixture (which handles temporary_settings properly) and only add the lifespan context in the async generator fixture. This avoids the ContextVar token error that occurs when temporary_settings context manager is entered/exited in different async contexts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4a4d2a1
1 hour ago
by desertaxle
© 2026 CodSpeed Technology
Home Terms Privacy Docs