Commit a8039cf
Add Debouncer — coalesce rapid workflow calls into one execution (#390)
Implements a debounce mechanism for DBOS workflows analogous to
dbos-transact-py _debouncer.py. Multiple calls with the same key within
a period are collapsed into a single user-workflow execution that runs
with the most recently supplied arguments.
Architecture:
- DebouncerServiceImpl: internal @workflow that runs a recv-loop,
absorbing messages until the debounce period times out or the absolute
debounceTimeout elapses, then starts the user workflow.
- Debouncer<R>: public fluent API. Enqueues the service workflow on
_dbos_internal_queue with a deduplicationId derived from (workflowName,
debounceKey). On DBOSQueueDuplicatedException, forwards a message to the
running debouncer and waits for an ack.
- DBOSExecutor.captureInvocation(): extracted from startWorkflow so
Debouncer can capture a lambda's workflow call without executing it.
- Auto-registration of DebouncerService in DBOS constructor so users
need no boilerplate setup.
- Internal system workflows filtered from getRegisteredWorkflows /
getRegisteredWorkflowInstances to keep public counts clean.
Usage:
```java
var handle = dbos.<String>debouncer()
.withDebounceTimeout(Duration.ofMinutes(5))
.debounce("key", Duration.ofSeconds(2), () -> svc.process(arg));
String result = handle.getResult();
```
Tests: 6 integration tests via Testcontainers Postgres covering
single-call, multi-call coalescing, absolute timeout, independent keys,
concurrent callers, and queue-based user workflow.
---------
Co-authored-by: Harry Pierson <harrypierson@hotmail.com>
Co-authored-by: Harry Pierson <harry.pierson@dbos.dev>1 parent caddbbb commit a8039cf
17 files changed
Lines changed: 1783 additions & 55 deletions
File tree
- transact/src
- main/java/dev/dbos/transact
- database
- dao
- execution
- internal
- workflow
- internal
- test/java/dev/dbos/transact
- client
- workflow
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
| |||
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| 71 | + | |
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
90 | 104 | | |
91 | 105 | | |
92 | 106 | | |
| |||
346 | 360 | | |
347 | 361 | | |
348 | 362 | | |
| 363 | + | |
| 364 | + | |
349 | 365 | | |
350 | 366 | | |
351 | 367 | | |
| |||
462 | 478 | | |
463 | 479 | | |
464 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
465 | 496 | | |
466 | 497 | | |
467 | 498 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
815 | 815 | | |
816 | 816 | | |
817 | 817 | | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
818 | 841 | | |
819 | 842 | | |
820 | 843 | | |
| |||
0 commit comments