diff --git a/README.md b/README.md index ea4a0f263..31f2e8c2d 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,9 @@ See the README.md file in each main sample directory for cut/paste Gradle comman - [**Exclude Workflow/ActivityTypes from Interceptors**](/core/src/main/java/io/temporal/samples/excludefrominterceptor): Demonstrates how to exclude certain workflow / activity types from interceptors. +- [**Early Return**](/core/src/main/java/io/temporal/samples/earlyreturn): Demonstrates how a client can start a new workflow and synchronously receive + a response mid-workflow, while the workflow continues to run to completion (using Update-with-Start). + #### SDK Metrics - [**Set up SDK metrics**](/core/src/main/java/io/temporal/samples/metrics): Demonstrates how to set up and scrape SDK metrics. diff --git a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java index 6ccb11da1..b5c3b46d3 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java @@ -76,7 +76,25 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) { + result.getTransactionId() + ")"); } catch (Exception e) { - System.err.println("Transaction initialization failed: " + e.getMessage()); + if (e.getCause() instanceof io.grpc.StatusRuntimeException) { + io.grpc.StatusRuntimeException sre = (io.grpc.StatusRuntimeException) e.getCause(); + + System.err.println("Workflow failed with StatusRuntimeException: " + sre.getMessage()); + System.err.println("Cause: " + e.getCause()); + + if (sre.getStatus().getCode() == io.grpc.Status.Code.PERMISSION_DENIED + && sre.getMessage() + .contains("ExecuteMultiOperation API is disabled on this namespace")) { + + // Inform the user that UpdateWithStart requires the ExecuteMultiOperation API to be + // enabled + System.err.println( + "UpdateWithStart requires the ExecuteMultiOperation API to be enabled on this namespace."); + } + } else { + System.err.println("Transaction initialization failed: " + e.getMessage()); + System.err.println("Cause: " + e.getCause()); + } } } diff --git a/core/src/main/java/io/temporal/samples/earlyreturn/TransactionWorkflowImpl.java b/core/src/main/java/io/temporal/samples/earlyreturn/TransactionWorkflowImpl.java index 8f7c86d34..71065f4bf 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/TransactionWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/TransactionWorkflowImpl.java @@ -45,7 +45,7 @@ public TxResult processTransaction(TransactionRequest txRequest) { } catch (Exception e) { initError = e; } finally { - initDone = true; + initDone = true; // Will unblock the early-return returnInitResult method } if (initError != null) { @@ -60,13 +60,14 @@ public TxResult processTransaction(TransactionRequest txRequest) { @Override public TxResult returnInitResult() { - Workflow.await(() -> initDone); + Workflow.await(() -> initDone); // Wait for the initialization step of the workflow to complete if (initError != null) { log.info("Initialization failed."); throw Workflow.wrap(initError); } - return new TxResult(tx.getId(), "Initialization successful"); + return new TxResult( + tx.getId(), "Initialization successful"); // Return the update result to the caller } }