Skip to content

Commit 40215c3

Browse files
committed
Use runDbosFunctionAsStep directly in Debouncer instead of manual inWorkflow/inStep checks
1 parent d77f70f commit 40215c3

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

transact/src/main/java/dev/dbos/transact/workflow/Debouncer.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,16 @@ private <T, E extends Exception> WorkflowHandle<T, E> debounceInternal(
232232

233233
DBOSExecutor.Invocation invocation = executor.captureInvocation(wfLambda);
234234

235-
// Inside a workflow, ID generation is wrapped in a step so replay is deterministic.
236-
DebounceIds ids;
237-
if (DBOS.inWorkflow() && !DBOS.inStep()) {
238-
ids =
239-
executor.runDbosFunctionAsStep(
240-
() ->
241-
new DebounceIds(
242-
DBOSContextHolder.get().getNextWorkflowId(UUID.randomUUID().toString()),
243-
UUID.randomUUID().toString()),
244-
"DBOS.assignDebounceIds",
245-
null);
246-
} else {
247-
ids =
248-
new DebounceIds(
249-
DBOSContextHolder.get().getNextWorkflowId(UUID.randomUUID().toString()),
250-
UUID.randomUUID().toString());
251-
}
235+
// Inside a workflow, ID generation is wrapped in a step so replay is deterministic;
236+
// runDbosFunctionAsStep runs the lambda directly when not in a workflow.
237+
DebounceIds ids =
238+
executor.runDbosFunctionAsStep(
239+
() ->
240+
new DebounceIds(
241+
DBOSContextHolder.get().getNextWorkflowId(UUID.randomUUID().toString()),
242+
UUID.randomUUID().toString()),
243+
"DBOS.assignDebounceIds",
244+
null);
252245
String userWorkflowId = ids.userWorkflowId();
253246
String messageId = ids.messageId();
254247

@@ -292,12 +285,10 @@ private <T, E extends Exception> WorkflowHandle<T, E> debounceInternal(
292285
// replay returns the same debouncer id and the subsequent send/getEvent steps stay
293286
// deterministic. Mirrors Python's call_function_as_step("DBOS.get_deduplicated_workflow").
294287
String existingDebouncerId =
295-
(DBOS.inWorkflow() && !DBOS.inStep())
296-
? executor.runDbosFunctionAsStep(
297-
() -> lookupExistingDebouncerId(debouncerDeduplicationId),
298-
"DBOS.lookupDebouncer",
299-
null)
300-
: lookupExistingDebouncerId(debouncerDeduplicationId);
288+
executor.runDbosFunctionAsStep(
289+
() -> lookupExistingDebouncerId(debouncerDeduplicationId),
290+
"DBOS.lookupDebouncer",
291+
null);
301292
if (existingDebouncerId == null) {
302293
// The existing debouncer finished between the enqueue attempt and now. Retry from
303294
// scratch — the next enqueue should succeed.

0 commit comments

Comments
 (0)