You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document Debounce, Cooldown, and update ConcurrencyLimit to Annotated style
Adds docs for the new Debounce and Cooldown admission controls, and rewrites
the ConcurrencyLimit section to use the Annotated style as the primary approach
(with a backward-compat note for the old string-name style).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -305,18 +305,18 @@ For more details on progress monitoring patterns and real-time observation, see
305
305
306
306
## Concurrency Control
307
307
308
-
Docket provides fine-grained concurrency control that allows you to limit the number of concurrent tasks based on specific argument values. This is essential for protecting shared resources, preventing overwhelming external services, and managing database connections.
308
+
Docket provides fine-grained concurrency control that limits how many tasks can run at the same time, based on specific argument values. This is useful for protecting shared resources, preventing overwhelming external services, and managing database connections.
309
309
310
-
### Basic Concurrency Limits
310
+
### Per-Argument Concurrency
311
311
312
-
Use `ConcurrencyLimit` to restrict concurrent execution based on task arguments:
312
+
Use `Annotated` to limit concurrency based on a specific argument value. Each distinct value gets its own independent limit:
Prior to 0.18, `ConcurrencyLimit` required passing the argument name as a
419
+
string: `ConcurrencyLimit("customer_id", max_concurrent=1)`. This style
420
+
still works but `Annotated` is preferred — it avoids the string-name
421
+
duplication and is consistent with Debounce, Cooldown, and other
422
+
dependencies.
423
+
424
+
## Debounce
425
+
426
+
Debounce is a leading-edge admission control: if a task was recently started, duplicate submissions within the window are silently dropped. This is useful for deduplicating rapid-fire events like webhooks, where the same event may arrive multiple times in quick succession.
427
+
428
+
### Per-Task Debounce
429
+
430
+
Apply debounce to the whole task so only one execution can start within the window:
1.**Choose appropriate argument names**: Use arguments that represent the resource you want to protect (database name, customer ID, API endpoint).
471
+
### How It Works
473
472
474
-
2.**Set reasonable limits**: Base limits on your system's capacity and external service constraints.
473
+
On entry, debounce atomically sets a Redis key with a TTL equal to the window (`SET key 1 NX PX window_ms`). If the key already exists, the task is dropped without rescheduling. The key expires naturally after the window, so no cleanup is needed.
475
474
476
-
3.**Use descriptive scopes**: When you have multiple unrelated concurrency controls, use different scopes to avoid conflicts.
475
+
## Cooldown
476
+
477
+
Cooldown is a trailing-edge admission control: if a task recently _succeeded_, new submissions are dropped. Unlike debounce, the cooldown window only starts after a successful execution — failed tasks don't trigger it, so they can be retried immediately.
0 commit comments