Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix background check replay code snippets for Java and Python #337

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/getting_started/dotnet/first_program_in_dotnet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public class MoneyTransferWorkflow
InitialInterval = TimeSpan.FromSeconds(1),
MaximumInterval = TimeSpan.FromSeconds(100),
BackoffCoefficient = 2,
MaximumAttempts = 500,
MaximumAttempts = 3,
NonRetryableErrorTypes = new[] { "InvalidAccountException", "InsufficientFundsException" }
};

Expand All @@ -178,7 +178,7 @@ public class MoneyTransferWorkflow
// If everything succeeds, return transfer complete
return $"Transfer complete (transaction IDs: {withdrawResult}, {depositResult})";
}
catch (ApplicationFailureException depositEx)
catch (Exception depositEx)
{
try
{
Expand All @@ -188,9 +188,9 @@ public class MoneyTransferWorkflow
new ActivityOptions { StartToCloseTimeout = TimeSpan.FromMinutes(5), RetryPolicy = retryPolicy }
);
// If refund is successful, but deposit failed
throw new ApplicationFailureException($"Failed to deposit money into account {details.TargetAccount}. Money returned to {details.SourceAccount}. Cause: {depositEx.Message}", depositEx);
throw new ApplicationFailureException($"Failed to deposit money into account {details.TargetAccount}. Money returned to {details.SourceAccount}.", depositEx);
}
catch (ApplicationFailureException refundEx)
catch (Exception refundEx)
{
// If both deposit and refund fail
throw new ApplicationFailureException($"Failed to deposit money into account {details.TargetAccount}. Money could not be returned to {details.SourceAccount}. Cause: {refundEx.Message}", refundEx);
Expand Down Expand Up @@ -351,7 +351,7 @@ You'll see a **Retry Policy** defined that looks like this:
InitialInterval = TimeSpan.FromSeconds(1),
MaximumInterval = TimeSpan.FromSeconds(100),
BackoffCoefficient = 2,
MaximumAttempts = 500,
MaximumAttempts = 3,
NonRetryableErrorTypes = new[] { "InvalidAccountException", "InsufficientFundsException" }
```
<!--SNIPEND-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,4 @@ Refer to the [Temporal documentation](https://docs.temporal.io/) for more.

## Conclusion

In this tutorial, you configured and deployed a baseline Temporal Service. Next, you can read about Temporal's [Visiblity features](https://docs.temporal.io/visibility) which require adding ElasticSearch to your deployment. You can also [learn more about the Temporal platform by following our self-paced online courses](https://learn.temporal.io/courses/), or talk to an expert about [Temporal Cloud](https://temporal.io/cloud).
In this tutorial, you configured and deployed a baseline Temporal Service. Next, you can read about Temporal's [Visiblity features](https://docs.temporal.io/visibility) which require adding ElasticSearch to your deployment. You can also [learn more about the Temporal platform by following our self-paced online courses](https://learn.temporal.io/courses/), or talk to an expert about [Temporal Cloud](https://temporal.io/cloud).
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,4 @@ Refer to the [Temporal documentation](https://docs.temporal.io/) for more.

## Conclusion

In this tutorial, you configured and deployed a baseline Temporal Service. Next, you can read about Temporal's [Visiblity features](https://docs.temporal.io/visibility) which require adding ElasticSearch to your deployment. You can also [learn more about the Temporal platform by following our self-paced online courses](https://learn.temporal.io/courses/), or talk to an expert about [Temporal Cloud](https://temporal.io/cloud).
In this tutorial, you configured and deployed a baseline Temporal Service. Next, you can read about Temporal's [Visiblity features](https://docs.temporal.io/visibility) which require adding ElasticSearch to your deployment. You can also [learn more about the Temporal platform by following our self-paced online courses](https://learn.temporal.io/courses/), or talk to an expert about [Temporal Cloud](https://temporal.io/cloud).
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,4 @@ Refer to the [Temporal documentation](https://docs.temporal.io/) for more.

## Conclusion

In this tutorial, you configured and deployed a baseline Temporal Service. Next, you can read about Temporal's [Visiblity features](https://docs.temporal.io/visibility) which require adding ElasticSearch to your deployment. You can also [learn more about the Temporal platform by following our self-paced online courses](https://learn.temporal.io/courses/), or talk to an expert about [Temporal Cloud](https://temporal.io/cloud).
In this tutorial, you configured and deployed a baseline Temporal Service. Next, you can read about Temporal's [Visiblity features](https://docs.temporal.io/visibility) which require adding ElasticSearch to your deployment. You can also [learn more about the Temporal platform by following our self-paced online courses](https://learn.temporal.io/courses/), or talk to an expert about [Temporal Cloud](https://temporal.io/cloud).
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public void testSuccessfulBackgroundCheckBoilerplateWithMocks(TestWorkflowEnviro
}

@Test
public void testSuccessfulReplayFromFile(TestWorkflowEnvironment testEnv, Worker worker,
BackgroundCheckReplayWorkflow workflow) throws Exception {
public void testSuccessfulReplayFromFile(BackgroundCheckReplayWorkflow workflow) throws Exception {

File eventHistoryFile = new File("backgroundcheck_workflow_event_history.json");

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/java/background-check/durable-execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ Add the Replay test to the set of application tests.
```java
// ...
@Test
public void testSuccessfulReplayFromFile(TestWorkflowEnvironment testEnv, Worker worker,
BackgroundCheckReplayWorkflow workflow) throws Exception {
public void testSuccessfulReplayFromFile(BackgroundCheckReplayWorkflow workflow) throws Exception {

File eventHistoryFile = new File("backgroundcheck_workflow_event_history.json");

assertDoesNotThrow(() -> WorkflowReplayer.replayWorkflowExecution(eventHistoryFile,
BackgroundCheckReplayWorkflowImpl.class));

}
}
```
<!--SNIPEND-->

Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/java/background-check/project-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ In the Temporal Java SDK programming model, a [Workflow Definition](https://docs
#### Boilerplate Workflow Interface {#workflow-code}

<!--SNIPSTART java-project-setup-chapter-boilerplate-workflow-interface-->
[BackgroundCheckBoilerplateWorkflow.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateWorkflow.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateWorkflow.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateWorkflow.java)
```java
package backgroundcheckboilerplate;

Expand Down Expand Up @@ -395,7 +395,7 @@ There can only be one Workflow Method per Workflow Definition.
Now that you've defined your Workflow Interface you can define its implementation.

<!--SNIPSTART java-project-setup-chapter-boilerplate-workflow-implementation-->
[BackgroundCheckBoilerplateWorkflowImpl.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateWorkflowImpl.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateWorkflowImpl.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateWorkflowImpl.java)
```java
package backgroundcheckboilerplate;

Expand Down Expand Up @@ -461,7 +461,7 @@ In the Temporal Java SDK programming model, an Activity is defined as an interfa
The `BackgroundCheckActivity` interface below is an example of a the first part defining an Activity

<!--SNIPSTART java-project-setup-chapter-boilerplate-activities-interface-->
[BackgroundCheckBoilerplateActivities.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateActivities.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateActivities.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateActivities.java)
```java
package backgroundcheckboilerplate;

Expand Down Expand Up @@ -491,7 +491,7 @@ Activity. There can multiple Activity Methods per Activity Definition.
Now that you've defined your Activity Interface you can define its implementation.

<!--SNIPSTART java-project-setup-chapter-boilerplate-activity-implementation-->
[BackgroundCheckBoilerplateActivitiesImpl.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateActivitiesImpl.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateActivitiesImpl.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/BackgroundCheckBoilerplateActivitiesImpl.java)
```java
package backgroundcheckboilerplate;

Expand Down Expand Up @@ -551,7 +551,7 @@ To run a Worker Process with a local development server, define the following st
Temporal recommends keeping Worker code separate from Workflow and Activity code.

<!--SNIPSTART java-project-setup-chapter-boilerplate-dev-service-worker-->
[workers/DevServerWorker.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/DevServerWorker.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/DevServerWorker.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/DevServerWorker.java)
```java
package backgroundcheckboilerplate.workers;

Expand Down Expand Up @@ -599,7 +599,7 @@ A Temporal Cloud Worker requires that you specify the following in the Client co
- Certificate and private key associated with the Namespace

<!--SNIPSTART java-project-setup-chapter-boilerplate-cloud-worker-->
[workers/CloudWorker.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/CloudWorker.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/CloudWorker.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/CloudWorker.java)
```java
package backgroundcheckboilerplate.workers;

Expand Down Expand Up @@ -758,7 +758,7 @@ Set IP address and port in the Service Stubs Options and the Namespace in the
Temporal Client options.

<!--SNIPSTART java-project-setup-chapter-self-hosted-worker-->
[workers/SelfHostedWorker.java](code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/SelfHostedWorker.java)
[docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/SelfHostedWorker.java](https://github.com/temporalio/temporal-learning/blob/main/docs/tutorials/java/background-check/code/backgroundcheck/src/main/java/backgroundcheckboilerplate/workers/SelfHostedWorker.java)
```java
package backgroundcheckboilerplate.workers;

Expand Down
7 changes: 7 additions & 0 deletions docs/tutorials/java/build-an-email-drip-campaign/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import subscription.model.*;
import subscription.workflows.SendEmailWorkflow;

@RestController
public class Controller {

@Autowired
WorkflowClient client;

```
<!--SNIPEND-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ async def test_execute_workflow():
# @@@SNIPSTART python-durability-chapter-replay-from-file-test
@pytest.mark.asyncio
async def test_replay_workflow_history_from_file():
async with await WorkflowEnvironment.start_time_skipping():
with open("tests/backgroundcheck_workflow_history.json", "r") as f:
history_json = json.load(f)
await Replayer(workflows=[BackgroundCheck]).replay_workflow(
WorkflowHistory.from_json("backgroundcheck_workflow", history_json)
)
with open("tests/backgroundcheck_workflow_history.json", "r") as f:
history_json = json.load(f)
await Replayer(workflows=[BackgroundCheck]).replay_workflow(
WorkflowHistory.from_json("backgroundcheck_workflow", history_json)
)
# @@@SNIPEND
11 changes: 5 additions & 6 deletions docs/tutorials/python/background-check/durable-execution.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,11 @@ If the Workflow Definition and the Event History are incompatible, then the test
```py
@pytest.mark.asyncio
async def test_replay_workflow_history_from_file():
async with await WorkflowEnvironment.start_time_skipping():
with open("tests/backgroundcheck_workflow_history.json", "r") as f:
history_json = json.load(f)
await Replayer(workflows=[BackgroundCheck]).replay_workflow(
WorkflowHistory.from_json("backgroundcheck_workflow", history_json)
)
with open("tests/backgroundcheck_workflow_history.json", "r") as f:
history_json = json.load(f)
await Replayer(workflows=[BackgroundCheck]).replay_workflow(
WorkflowHistory.from_json("backgroundcheck_workflow", history_json)
)
```
<!--SNIPEND-->

Expand Down