From 02ff9ef3476e6d4d3e891970d666c5cc6c262a48 Mon Sep 17 00:00:00 2001 From: Steve Androulakis Date: Sun, 10 Nov 2024 11:18:11 -0800 Subject: [PATCH 1/5] client error detailed logged (to catch ExecuteMultiOperation disabled on namespace) --- .../java/io/temporal/samples/earlyreturn/EarlyReturnClient.java | 1 + 1 file changed, 1 insertion(+) 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..be307731f 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java @@ -77,6 +77,7 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) { + ")"); } catch (Exception e) { System.err.println("Transaction initialization failed: " + e.getMessage()); + System.err.println("Cause: " + e.getCause()); } } From 138a41d5b0f57b348def46fdd70fd4a68fbf33ed Mon Sep 17 00:00:00 2001 From: Steve Androulakis Date: Sun, 10 Nov 2024 11:20:13 -0800 Subject: [PATCH 2/5] code comments --- .../samples/earlyreturn/TransactionWorkflowImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 } } From c693a652f56896e330630df934ff082254d051f7 Mon Sep 17 00:00:00 2001 From: Steve Androulakis Date: Sun, 10 Nov 2024 11:23:51 -0800 Subject: [PATCH 3/5] Early Return in main README --- README.md | 3 +++ 1 file changed, 3 insertions(+) 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. From ef45d74d46b2841972840384fc396b840721cdd6 Mon Sep 17 00:00:00 2001 From: Steve Androulakis Date: Tue, 12 Nov 2024 09:58:29 -0800 Subject: [PATCH 4/5] Explicit catching of ExecuteMultiOperation exception cause --- .../earlyreturn/EarlyReturnClient.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 be307731f..79dd638c7 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java @@ -76,8 +76,24 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) { + result.getTransactionId() + ")"); } catch (Exception e) { - System.err.println("Transaction initialization failed: " + e.getMessage()); - System.err.println("Cause: " + e.getCause()); + 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()); + } } } From e05af76e3e4fa0601471cb6a35445be9d2e92244 Mon Sep 17 00:00:00 2001 From: Steve Androulakis Date: Tue, 12 Nov 2024 10:04:29 -0800 Subject: [PATCH 5/5] spotless fixes --- .../io/temporal/samples/earlyreturn/EarlyReturnClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 79dd638c7..b5c3b46d3 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java @@ -86,7 +86,8 @@ private static void runWorkflowWithUpdateWithStart(WorkflowClient client) { && sre.getMessage() .contains("ExecuteMultiOperation API is disabled on this namespace")) { - // Inform the user that UpdateWithStart requires the ExecuteMultiOperation API to be enabled + // 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."); }