From 159c7b8bfe36b1d8c32d2813089a47bd569c7008 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 17 Feb 2025 22:14:41 -0800 Subject: [PATCH 1/9] Update Nexus Sample for v1.28.0 --- .../samples/nexus/handler/NexusServiceImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java index d7fda2fd9..e65df3df9 100644 --- a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java @@ -34,12 +34,12 @@ public class NexusServiceImpl { @OperationImpl public OperationHandler echo() { - // OperationHandler.sync is a meant for exposing simple RPC handlers. + // WorkflowClientOperationHandlers.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( - // The method is for making arbitrary short calls to other services or databases, or - // perform simple computations such as this one. Users can also access a workflow client by - // calling - // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as + // The method is for to make arbitrary short calls to other services or databases, or + // perform simple computations such as this one. + // Users can also access a client by calling + // Nexus.getOperationContext().getWorkflowClient(ctx) to mae arbitrary calls such as // signaling, querying, or listing workflows. (ctx, details, input) -> new NexusService.EchoOutput(input.getMessage())); } From f0f6a51dc59f1216507bcc4fd0f84f619c090584 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 17 Feb 2025 22:17:21 -0800 Subject: [PATCH 2/9] fix typo --- .../temporal/samples/nexus/handler/NexusServiceImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java index e65df3df9..de967848c 100644 --- a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java @@ -34,12 +34,11 @@ public class NexusServiceImpl { @OperationImpl public OperationHandler echo() { - // WorkflowClientOperationHandlers.sync is a meant for exposing simple RPC handlers. + // OperationHandler.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( // The method is for to make arbitrary short calls to other services or databases, or - // perform simple computations such as this one. - // Users can also access a client by calling - // Nexus.getOperationContext().getWorkflowClient(ctx) to mae arbitrary calls such as + // perform simple computations such as this one. Users can also access a workflow client by calling + // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as // signaling, querying, or listing workflows. (ctx, details, input) -> new NexusService.EchoOutput(input.getMessage())); } From 9818e87cb549e2b8f1f0f33543d4fec9e01f20a4 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 18 Feb 2025 21:43:13 -0800 Subject: [PATCH 3/9] Small updates --- .../io/temporal/samples/nexus/handler/NexusServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java index de967848c..df57c743c 100644 --- a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java @@ -37,7 +37,8 @@ public OperationHandler echo() // OperationHandler.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( // The method is for to make arbitrary short calls to other services or databases, or - // perform simple computations such as this one. Users can also access a workflow client by calling + // perform simple computations such as this one. Users can also access a workflow client by + // calling // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as // signaling, querying, or listing workflows. (ctx, details, input) -> new NexusService.EchoOutput(input.getMessage())); From c46211ae86ce64155d592893cc9d55590b44587b Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 18 Feb 2025 22:50:26 -0800 Subject: [PATCH 4/9] Add Nexus Cancellation Sample --- .../samples/nexuscancellation/README.MD | 36 ++++++++ .../caller/CallerStarter.java | 46 ++++++++++ .../caller/CallerWorker.java | 50 +++++++++++ .../caller/HelloCallerWorkflow.java | 10 +++ .../caller/HelloCallerWorkflowImpl.java | 89 +++++++++++++++++++ .../handler/HandlerWorker.java | 42 +++++++++ .../handler/HelloHandlerWorkflowImpl.java | 48 ++++++++++ 7 files changed, 321 insertions(+) create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/README.MD create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerStarter.java create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/handler/HandlerWorker.java create mode 100644 core/src/main/java/io/temporal/samples/nexuscancellation/handler/HelloHandlerWorkflowImpl.java diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/README.MD b/core/src/main/java/io/temporal/samples/nexuscancellation/README.MD new file mode 100644 index 000000000..cf39c85c4 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/README.MD @@ -0,0 +1,36 @@ +# Nexus Cancellation + +This sample shows how to cancel a Nexus operation from a caller workflow. + +From more details on Nexus and how to setup to run this samples please see the [Nexus Sample](../nexus/README.MD). + +In separate terminal windows: + +### Nexus handler worker + +``` +./gradlew -q execute -PmainClass=io.temporal.samples.nexuscancellation.handler.HandlerWorker \ + --args="-target-host localhost:7233 -namespace my-target-namespace" +``` + +### Nexus caller worker + +``` +./gradlew -q execute -PmainClass=io.temporal.samples.nexuscancellation.caller.CallerWorker \ + --args="-target-host localhost:7233 -namespace my-caller-namespace" +``` + +### Start caller workflow + +``` +./gradlew -q execute -PmainClass=io.temporal.samples.nexuscancellation.caller.CallerStarter \ + --args="-target-host localhost:7233 -namespace my-caller-namespace" +``` + +### Output + +which should result in: +``` +INFO i.t.s.n.caller.CallerStarter - Started workflow workflowId: 326732dd-a2b1-4de7-9ddd-dcee4f9f0229 runId: d580499f-79d5-461d-bd49-6248b4e522ae +INFO i.t.s.n.caller.CallerStarter - Workflow result: Hallo Nexus πŸ‘‹ +``` diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerStarter.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerStarter.java new file mode 100644 index 000000000..1ee705b1a --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerStarter.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.nexuscancellation.caller; + +import io.temporal.api.common.v1.WorkflowExecution; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.samples.nexus.options.ClientOptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CallerStarter { + private static final Logger logger = LoggerFactory.getLogger(CallerStarter.class); + + public static void main(String[] args) { + WorkflowClient client = ClientOptions.getWorkflowClient(args); + + WorkflowOptions workflowOptions = + WorkflowOptions.newBuilder().setTaskQueue(CallerWorker.DEFAULT_TASK_QUEUE_NAME).build(); + HelloCallerWorkflow helloWorkflow = + client.newWorkflowStub(HelloCallerWorkflow.class, workflowOptions); + WorkflowExecution execution = WorkflowClient.start(helloWorkflow::hello, "Nexus"); + logger.info( + "Started workflow workflowId: {} runId: {}", + execution.getWorkflowId(), + execution.getRunId()); + logger.info("Workflow result: {}", helloWorkflow.hello("Nexus")); + } +} diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java new file mode 100644 index 000000000..e1c26cb6d --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.nexuscancellation.caller; + +import io.temporal.client.WorkflowClient; +import io.temporal.samples.nexus.options.ClientOptions; +import io.temporal.worker.Worker; +import io.temporal.worker.WorkerFactory; +import io.temporal.worker.WorkflowImplementationOptions; +import io.temporal.workflow.NexusServiceOptions; +import java.util.Collections; + +public class CallerWorker { + public static final String DEFAULT_TASK_QUEUE_NAME = "my-caller-workflow-task-queue"; + + public static void main(String[] args) { + WorkflowClient client = ClientOptions.getWorkflowClient(args); + + WorkerFactory factory = WorkerFactory.newInstance(client); + + Worker worker = factory.newWorker(DEFAULT_TASK_QUEUE_NAME); + worker.registerWorkflowImplementationTypes( + WorkflowImplementationOptions.newBuilder() + .setNexusServiceOptions( + Collections.singletonMap( + "NexusService", + NexusServiceOptions.newBuilder().setEndpoint("my-nexus-endpoint-name").build())) + .build(), + HelloCallerWorkflowImpl.class); + + factory.start(); + } +} diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java new file mode 100644 index 000000000..a585d713c --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java @@ -0,0 +1,10 @@ +package io.temporal.samples.nexuscancellation.caller; + +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; + +@WorkflowInterface +public interface HelloCallerWorkflow { + @WorkflowMethod + String hello(String message); +} diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java new file mode 100644 index 000000000..75cd19cbd --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.nexuscancellation.caller; + +import static io.temporal.samples.nexus.service.NexusService.Language.*; + +import io.temporal.failure.CanceledFailure; +import io.temporal.failure.NexusOperationFailure; +import io.temporal.samples.nexus.service.NexusService; +import io.temporal.workflow.*; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +public class HelloCallerWorkflowImpl implements HelloCallerWorkflow { + private static final NexusService.Language[] languages = + new NexusService.Language[] {EN, FR, DE, ES, TR}; + NexusService nexusService = + Workflow.newNexusServiceStub( + NexusService.class, + NexusServiceOptions.newBuilder() + .setOperationOptions( + NexusOperationOptions.newBuilder() + .setScheduleToCloseTimeout(Duration.ofSeconds(10)) + .build()) + .build()); + + @Override + public String hello(String message) { + List> results = new ArrayList<>(languages.length); + + /* + * Create our CancellationScope. Within this scope we call the nexus operation asynchronously + * hello method asynchronously for each of our defined languages. + */ + CancellationScope scope = + Workflow.newCancellationScope( + () -> { + for (NexusService.Language language : languages) { + results.add( + Async.function( + nexusService::hello, new NexusService.HelloInput(message, language))); + } + }); + + /* + * Execute all nexus operations within the CancellationScope. Note that this execution is + * non-blocking as the code inside our cancellation scope is also non-blocking. + */ + scope.run(); + + // We use "anyOf" here to wait for one of the nexus operation invocations to return + NexusService.HelloOutput result = Promise.anyOf(results).get(); + + // Trigger cancellation of all uncompleted nexus operations invocations within the cancellation + // scope + scope.cancel(); + // Optionally, wait for all nexus operations to complete + for (Promise promise : results) { + try { + promise.get(); + } catch (NexusOperationFailure e) { + // If the operation was cancelled, we can ignore the failure + if (e.getCause() instanceof CanceledFailure) { + continue; + } + throw e; + } + } + return result.getMessage(); + } +} diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/handler/HandlerWorker.java b/core/src/main/java/io/temporal/samples/nexuscancellation/handler/HandlerWorker.java new file mode 100644 index 000000000..a70a47abe --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/handler/HandlerWorker.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.nexuscancellation.handler; + +import io.temporal.client.WorkflowClient; +import io.temporal.samples.nexus.handler.NexusServiceImpl; +import io.temporal.samples.nexus.options.ClientOptions; +import io.temporal.worker.Worker; +import io.temporal.worker.WorkerFactory; + +public class HandlerWorker { + public static final String DEFAULT_TASK_QUEUE_NAME = "my-handler-task-queue"; + + public static void main(String[] args) { + WorkflowClient client = ClientOptions.getWorkflowClient(args); + + WorkerFactory factory = WorkerFactory.newInstance(client); + + Worker worker = factory.newWorker(DEFAULT_TASK_QUEUE_NAME); + worker.registerWorkflowImplementationTypes(HelloHandlerWorkflowImpl.class); + worker.registerNexusServiceImplementation(new NexusServiceImpl()); + + factory.start(); + } +} diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/handler/HelloHandlerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexuscancellation/handler/HelloHandlerWorkflowImpl.java new file mode 100644 index 000000000..246c25e93 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/handler/HelloHandlerWorkflowImpl.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.nexuscancellation.handler; + +import io.temporal.failure.ApplicationFailure; +import io.temporal.samples.nexus.handler.HelloHandlerWorkflow; +import io.temporal.samples.nexus.service.NexusService; +import io.temporal.workflow.Workflow; +import java.time.Duration; + +public class HelloHandlerWorkflowImpl implements HelloHandlerWorkflow { + @Override + public NexusService.HelloOutput hello(NexusService.HelloInput input) { + // Sleep for a random duration to simulate some work + Workflow.sleep(Duration.ofSeconds(Workflow.newRandom().nextInt(5))); + switch (input.getLanguage()) { + case EN: + return new NexusService.HelloOutput("Hello " + input.getName() + " πŸ‘‹"); + case FR: + return new NexusService.HelloOutput("Bonjour " + input.getName() + " πŸ‘‹"); + case DE: + return new NexusService.HelloOutput("Hallo " + input.getName() + " πŸ‘‹"); + case ES: + return new NexusService.HelloOutput("Β‘Hola! " + input.getName() + " πŸ‘‹"); + case TR: + return new NexusService.HelloOutput("Merhaba " + input.getName() + " πŸ‘‹"); + } + throw ApplicationFailure.newFailure( + "Unsupported language: " + input.getLanguage(), "UNSUPPORTED_LANGUAGE"); + } +} From 3107b3266bb83bf8a4e9b986694acdc24362b865 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 26 Feb 2025 15:45:23 -0800 Subject: [PATCH 5/9] Update cancellation sample --- .../samples/nexuscancellation/caller/CallerWorker.java | 3 ++- .../nexuscancellation/caller/HelloCallerWorkflowImpl.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java index e1c26cb6d..37f5eaa5f 100644 --- a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/CallerWorker.java @@ -21,6 +21,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.samples.nexus.options.ClientOptions; +import io.temporal.samples.nexus.service.NexusService; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkflowImplementationOptions; @@ -40,7 +41,7 @@ public static void main(String[] args) { WorkflowImplementationOptions.newBuilder() .setNexusServiceOptions( Collections.singletonMap( - "NexusService", + NexusService.class.getSimpleName(), NexusServiceOptions.newBuilder().setEndpoint("my-nexus-endpoint-name").build())) .build(), HelloCallerWorkflowImpl.class); diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java index 75cd19cbd..f1121cdab 100644 --- a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java @@ -73,6 +73,9 @@ public String hello(String message) { // scope scope.cancel(); // Optionally, wait for all nexus operations to complete + // + // Note: Once the workflow completes any pending cancellation requests are dropped by the + // server. for (Promise promise : results) { try { promise.get(); From 59a785cc00082e60b7cfeb50895255b0af7367c4 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 26 Feb 2025 15:47:17 -0800 Subject: [PATCH 6/9] fix typo --- .../io/temporal/samples/nexus/handler/NexusServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java index df57c743c..d7fda2fd9 100644 --- a/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java +++ b/core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java @@ -36,7 +36,7 @@ public class NexusServiceImpl { public OperationHandler echo() { // OperationHandler.sync is a meant for exposing simple RPC handlers. return OperationHandler.sync( - // The method is for to make arbitrary short calls to other services or databases, or + // The method is for making arbitrary short calls to other services or databases, or // perform simple computations such as this one. Users can also access a workflow client by // calling // Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as From d2caa2a24ce7c402ee39313a59c53303fcb255b0 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Wed, 26 Feb 2025 15:53:01 -0800 Subject: [PATCH 7/9] run license check --- .../caller/HelloCallerWorkflow.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java index a585d713c..7f77cc68c 100644 --- a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflow.java @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package io.temporal.samples.nexuscancellation.caller; import io.temporal.workflow.WorkflowInterface; From 40694f0b84704e0467ed2d18b97abb82734cd529 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Thu, 27 Feb 2025 13:45:43 -0800 Subject: [PATCH 8/9] add log --- .../nexuscancellation/caller/HelloCallerWorkflowImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java index f1121cdab..bdaaab0ac 100644 --- a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java @@ -19,17 +19,20 @@ package io.temporal.samples.nexuscancellation.caller; -import static io.temporal.samples.nexus.service.NexusService.Language.*; - import io.temporal.failure.CanceledFailure; import io.temporal.failure.NexusOperationFailure; import io.temporal.samples.nexus.service.NexusService; import io.temporal.workflow.*; +import org.slf4j.Logger; + import java.time.Duration; import java.util.ArrayList; import java.util.List; +import static io.temporal.samples.nexus.service.NexusService.Language.*; + public class HelloCallerWorkflowImpl implements HelloCallerWorkflow { + public static final Logger log = Workflow.getLogger(HelloCallerWorkflowImpl.class); private static final NexusService.Language[] languages = new NexusService.Language[] {EN, FR, DE, ES, TR}; NexusService nexusService = @@ -82,6 +85,7 @@ public String hello(String message) { } catch (NexusOperationFailure e) { // If the operation was cancelled, we can ignore the failure if (e.getCause() instanceof CanceledFailure) { + log.info("Operation was cancelled"); continue; } throw e; From 71d795ca7985a604073b2a364fbedd184abf7b1a Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Thu, 27 Feb 2025 13:51:53 -0800 Subject: [PATCH 9/9] run spotless --- .../nexuscancellation/caller/HelloCallerWorkflowImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java index bdaaab0ac..bc3666147 100644 --- a/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/nexuscancellation/caller/HelloCallerWorkflowImpl.java @@ -19,17 +19,16 @@ package io.temporal.samples.nexuscancellation.caller; +import static io.temporal.samples.nexus.service.NexusService.Language.*; + import io.temporal.failure.CanceledFailure; import io.temporal.failure.NexusOperationFailure; import io.temporal.samples.nexus.service.NexusService; import io.temporal.workflow.*; -import org.slf4j.Logger; - import java.time.Duration; import java.util.ArrayList; import java.util.List; - -import static io.temporal.samples.nexus.service.NexusService.Language.*; +import org.slf4j.Logger; public class HelloCallerWorkflowImpl implements HelloCallerWorkflow { public static final Logger log = Workflow.getLogger(HelloCallerWorkflowImpl.class);