Skip to content

Commit 2b87be2

Browse files
authored
Plumb @Workflow.maxRecoveryAttempts thru to executor (#199)
Fixes #198
1 parent b376708 commit 2b87be2

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

transact/src/main/java/dev/dbos/transact/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public class Constants {
1818
public static final String DBOS_SCHEDULER_QUEUE = "schedulerQueue";
1919

2020
public static final String SYSTEM_JDBC_URL_ENV_VAR = "DBOS_SYSTEM_JDBC_URL";
21+
22+
public static final int DEFAULT_MAX_RECOVERY_ATTEMPTS = 100;
2123
}

transact/src/main/java/dev/dbos/transact/DBOSClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ public <T, E extends Exception> WorkflowHandle<T, E> enqueueWorkflow(
286286
options.workflowName(), "EnqueueOptions workflowName must not be null"),
287287
Objects.requireNonNull(options.className(), "EnqueueOptions className must not be null"),
288288
Objects.requireNonNullElse(options.instanceName(), ""),
289+
null,
289290
args,
290291
new ExecuteWorkflowOptions(
291292
Objects.requireNonNullElseGet(options.workflowId(), () -> UUID.randomUUID().toString()),

transact/src/main/java/dev/dbos/transact/execution/DBOSExecutor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,11 +892,14 @@ public <T, E extends Exception> WorkflowHandle<T, E> executeWorkflow(
892892
WorkflowInfo parent,
893893
CompletableFuture<String> latch) {
894894

895+
Integer maxRetries = workflow.maxRecoveryAttempts() > 0 ? workflow.maxRecoveryAttempts() : null;
896+
895897
if (options.queueName != null) {
896898
return enqueueWorkflow(
897899
workflow.name(),
898900
workflow.className(),
899901
workflow.instanceName(),
902+
maxRetries,
900903
args,
901904
options,
902905
parent,
@@ -924,6 +927,7 @@ public <T, E extends Exception> WorkflowHandle<T, E> executeWorkflow(
924927
workflow.name(),
925928
workflow.className(),
926929
workflow.instanceName(),
930+
maxRetries,
927931
args,
928932
workflowId,
929933
null,
@@ -1022,6 +1026,7 @@ public static <T, E extends Exception> WorkflowHandle<T, E> enqueueWorkflow(
10221026
String name,
10231027
String className,
10241028
String instanceName,
1029+
Integer maxRetries,
10251030
Object[] args,
10261031
ExecuteWorkflowOptions options,
10271032
WorkflowInfo parent,
@@ -1051,6 +1056,7 @@ public static <T, E extends Exception> WorkflowHandle<T, E> enqueueWorkflow(
10511056
name,
10521057
className,
10531058
instanceName,
1059+
maxRetries,
10541060
args,
10551061
workflowId,
10561062
queueName,
@@ -1084,6 +1090,7 @@ private static WorkflowInitResult preInvokeWorkflow(
10841090
String workflowName,
10851091
String className,
10861092
String instanceName,
1093+
Integer maxRetries,
10871094
Object[] inputs,
10881095
String workflowId,
10891096
String queueName,
@@ -1106,6 +1113,7 @@ private static WorkflowInitResult preInvokeWorkflow(
11061113
Long deadlineEpochMs =
11071114
queueName != null ? null : deadline != null ? deadline.toEpochMilli() : null;
11081115

1116+
final int retries = maxRetries == null ? Constants.DEFAULT_MAX_RECOVERY_ATTEMPTS : maxRetries;
11091117
WorkflowStatusInternal workflowStatusInternal =
11101118
new WorkflowStatusInternal(
11111119
workflowId,
@@ -1135,7 +1143,7 @@ private static WorkflowInitResult preInvokeWorkflow(
11351143
WorkflowInitResult[] initResult = {null};
11361144
DbRetry.run(
11371145
() -> {
1138-
initResult[0] = systemDatabase.initWorkflowStatus(workflowStatusInternal, 3);
1146+
initResult[0] = systemDatabase.initWorkflowStatus(workflowStatusInternal, retries);
11391147
});
11401148

11411149
if (parentWorkflow != null) {

transact/src/test/java/dev/dbos/transact/database/DisruptiveServiceImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88

99
import javax.sql.DataSource;
1010

11-
import org.slf4j.Logger;
12-
import org.slf4j.LoggerFactory;
13-
1411
public class DisruptiveServiceImpl implements DisruptiveService {
1512

16-
private static final Logger logger = LoggerFactory.getLogger(DisruptiveServiceImpl.class);
17-
1813
private DisruptiveService self;
1914
private DataSource ds;
2015

0 commit comments

Comments
 (0)