From a5fea80701cb6f8ffaacdd3ea085ecff45fbce54 Mon Sep 17 00:00:00 2001 From: GSmithApps Date: Thu, 2 Jan 2025 14:05:50 -0600 Subject: [PATCH 1/4] Grant notes while onboarding to DSE and taking 102 courses. --- .vscode/settings.json | 6 ------ exercises/debug-activity/README.md | 10 +++++++--- .../debug-activity/practice/tests/test_activities.py | 2 +- .../debug-activity/practice/tests/test_workflow.py | 2 +- exercises/durable-execution/README.md | 6 +++++- exercises/durable-execution/practice/workflow.py | 4 ++-- exercises/testing-code/README.md | 8 +++++--- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index eed5603..929cc5f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,15 +3,9 @@ "editor.defaultFormatter": "ms-python.black-formatter" }, "python.formatting.provider": "none", - "workbench.editorAssociations": { - "README.md": "vscode.markdown.preview.editor" - }, "go.alternateTools": { "go": "/home/linuxbrew/.linuxbrew/bin/go", }, - "markdown.styles": [ - "style.css" - ], "terminal.integrated.defaultProfile.linux": "bash", "terminal.integrated.profiles.linux": { "bash": { diff --git a/exercises/debug-activity/README.md b/exercises/debug-activity/README.md index 6abb7c7..3f49b78 100644 --- a/exercises/debug-activity/README.md +++ b/exercises/debug-activity/README.md @@ -13,6 +13,10 @@ Make your changes to the code in the `practice` subdirectory (look for the code). If you need a hint or want to verify your changes, look at the complete version in the `solution` subdirectory. +### Prerequisite: Start the Temporal Service + +1. Start the Temporal Service with `temporal server start-dev` + ## Prerequisite: Ensure Your Virtual Environment is activated If you haven't already started the Translation Microservice used by this exercise, @@ -44,7 +48,7 @@ does by using the Web UI to interpret the Event History. Open the Web UI and navigate to the detail page for the Workflow Execution you just ran, which has the Workflow Type `PizzaWorkflow` -and Workflow ID `pizza-workflow-order-XD001`). +and Workflow ID `pizza-workflow-order-XD001`. If the detail page still shows a status of Running, wait a few seconds and refresh the page. Once the page shows a status of Completed, use @@ -87,7 +91,7 @@ Take a moment to switch to the Compact view, and if one of the rows in the table is expanded, click to collapse it. Do you find that this view makes it easier to see the Activities and Timer that ran during the execution? -Click "Expand All" near the upper-right corner of this table. Do you find +Click "Expand All" at the top of this table. Do you find that this helps you to correlate Events related to the Activities and Timer? Since the Web UI remembers the current view, be sure to click "Collapse All" @@ -178,7 +182,7 @@ in the Workflow code, rather than in an Activity, since that is typically not prone to failure and unlikely to affect whether the Workflow executes in a deterministic manner. This exercise implemented it in the Activity, since you can deploy a fix to Activity code without a risk of causing a -non-deterministic error. Later in this course, you'll learn how to safely +non-deterministic error. As you learned earlier in this course, there are also ways to safely deploy changes to Workflow Definitions. ### This is the end of the exercise. diff --git a/exercises/debug-activity/practice/tests/test_activities.py b/exercises/debug-activity/practice/tests/test_activities.py index 83fca68..d6af42a 100644 --- a/exercises/debug-activity/practice/tests/test_activities.py +++ b/exercises/debug-activity/practice/tests/test_activities.py @@ -42,7 +42,7 @@ async def test_send_bill_typical_order(): customer_id=12983, order_number="XD001", description="2 large cheese pizzas", - amount=2600, + amount=2600, # amount does not qualify for discount ) activity_environment = ActivityEnvironment() activities = PizzaOrderActivities() diff --git a/exercises/debug-activity/practice/tests/test_workflow.py b/exercises/debug-activity/practice/tests/test_workflow.py index 1c913da..56b3bca 100644 --- a/exercises/debug-activity/practice/tests/test_workflow.py +++ b/exercises/debug-activity/practice/tests/test_workflow.py @@ -58,7 +58,7 @@ async def test_failed_pizza_order_outside_delivery_error(): id="test-translation-workflow-id", task_queue="test-pizza-order", ) - assert isinstance(e.value.cause, ApplicationError) + assert isinstance(e.value, WorkflowFailureError) assert "customer lives outside the service area" == str(e.value.cause) diff --git a/exercises/durable-execution/README.md b/exercises/durable-execution/README.md index f19dd0c..233dcdc 100644 --- a/exercises/durable-execution/README.md +++ b/exercises/durable-execution/README.md @@ -10,7 +10,7 @@ During this exercise, you will Make your changes to the code in the `practice` subdirectory (look for `TODO` comments that will guide you to where you should make changes to the code). If you need a hint or want to verify your changes, look at the complete version in the `solution` subdirectory. -## Prerequisite: Ensure the Microservice is running and your Virtual Environment is activated +## Prerequisite: Ensure your Virtual Environment is activated, the Microservice is running, and the Temporal Service is running If you haven't already started the Translation Microservice used by this exercise, do so in a separate terminal. @@ -32,6 +32,10 @@ environment** 3. Run the microservice 1. `python microservice.py` +### Start the Temporal Service + +1. Start the Temporal Service with `temporal server start-dev` + ## Part A: Add Logging to the Workflow Code 1. Edit the `workflow.py` file diff --git a/exercises/durable-execution/practice/workflow.py b/exercises/durable-execution/practice/workflow.py index 6861014..6ca20f8 100644 --- a/exercises/durable-execution/practice/workflow.py +++ b/exercises/durable-execution/practice/workflow.py @@ -44,11 +44,11 @@ async def run(self, input: TranslationWorkflowInput) -> TranslationWorkflowOutpu # TODO PART D:Add a Timer that sleeps for 10 seconds - # TODO PART A:Add a log message using the workflow logger at the debug level - # stating that the Activity has been invoked. Include the term and language code. goodbye_input = TranslationActivityInput( language_code=input.language_code, term="goodbye" ) + # TODO PART A:Add a log message using the workflow logger at the debug level + # stating that the Activity has been invoked. Include the term and language code. goodbye_result = await workflow.execute_activity_method( TranslationActivities.translate_term, goodbye_input, diff --git a/exercises/testing-code/README.md b/exercises/testing-code/README.md index 1489e4e..b8296db 100644 --- a/exercises/testing-code/README.md +++ b/exercises/testing-code/README.md @@ -44,7 +44,8 @@ test, which you'll find in the `test_activities.py` file in the `tests` director Since the test runs the Activity, which in turn calls the microservice to do the translation, you'll begin by starting that. -1. Run the `python -m pytest` command to execute the provided test +1. Navigate to `exercises/testing-code/practice` +2. Run the `python -m pytest` command to execute the provided test ## Part B: Add another test case for the Activity @@ -136,11 +137,12 @@ continue with the following steps. ``` 4. Create a new async function to mock your Activity. 1. Name it `translate_term_mocked_french` and decorate it with - `@activity.defn(name="translate_term")`. The function should take `TranslationActivityInput` + `@activity.defn(name="translate_term")`. The function's signature should + match that of the activity it is mocking. 2. In the body of your new mocked Activity, write an if statement that returns a new `TranslationActivityOutput` object containing `Bonjour` if the term that was passed in via the `TranslationActivityInput` was `hello`. Otherwise - return a new `TranslationActivityObject` containing `Au revoir`. + return a new `TranslationActivityOutput` containing `Au revoir`. 3. The full mocked Activity is shown below: ```python @activity.defn(name="translate_term") From d80a1b4a7381c8b65a2f9cd7b30203cc1f5735e5 Mon Sep 17 00:00:00 2001 From: GSmithApps Date: Wed, 8 Jan 2025 13:30:25 -0600 Subject: [PATCH 2/4] removed changes in settings.json --- .vscode/settings.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 929cc5f..eed5603 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,9 +3,15 @@ "editor.defaultFormatter": "ms-python.black-formatter" }, "python.formatting.provider": "none", + "workbench.editorAssociations": { + "README.md": "vscode.markdown.preview.editor" + }, "go.alternateTools": { "go": "/home/linuxbrew/.linuxbrew/bin/go", }, + "markdown.styles": [ + "style.css" + ], "terminal.integrated.defaultProfile.linux": "bash", "terminal.integrated.profiles.linux": { "bash": { From 9c6c77a52a23aaa71eb5e1a1087dad13f08d9210 Mon Sep 17 00:00:00 2001 From: GSmithApps Date: Wed, 8 Jan 2025 13:42:08 -0600 Subject: [PATCH 3/4] removed notes to remind user to start the server --- exercises/debug-activity/README.md | 4 ---- exercises/durable-execution/README.md | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/exercises/debug-activity/README.md b/exercises/debug-activity/README.md index 3f49b78..21a09d3 100644 --- a/exercises/debug-activity/README.md +++ b/exercises/debug-activity/README.md @@ -13,10 +13,6 @@ Make your changes to the code in the `practice` subdirectory (look for the code). If you need a hint or want to verify your changes, look at the complete version in the `solution` subdirectory. -### Prerequisite: Start the Temporal Service - -1. Start the Temporal Service with `temporal server start-dev` - ## Prerequisite: Ensure Your Virtual Environment is activated If you haven't already started the Translation Microservice used by this exercise, diff --git a/exercises/durable-execution/README.md b/exercises/durable-execution/README.md index 233dcdc..f19dd0c 100644 --- a/exercises/durable-execution/README.md +++ b/exercises/durable-execution/README.md @@ -10,7 +10,7 @@ During this exercise, you will Make your changes to the code in the `practice` subdirectory (look for `TODO` comments that will guide you to where you should make changes to the code). If you need a hint or want to verify your changes, look at the complete version in the `solution` subdirectory. -## Prerequisite: Ensure your Virtual Environment is activated, the Microservice is running, and the Temporal Service is running +## Prerequisite: Ensure the Microservice is running and your Virtual Environment is activated If you haven't already started the Translation Microservice used by this exercise, do so in a separate terminal. @@ -32,10 +32,6 @@ environment** 3. Run the microservice 1. `python microservice.py` -### Start the Temporal Service - -1. Start the Temporal Service with `temporal server start-dev` - ## Part A: Add Logging to the Workflow Code 1. Edit the `workflow.py` file From 5ba3cc0c89798b737deffc4b3d2c8f35f31ada25 Mon Sep 17 00:00:00 2001 From: Mason Egger Date: Mon, 17 Mar 2025 18:10:03 -0500 Subject: [PATCH 4/4] fixing broken stuff that shouldnt be broken but was --- exercises/debug-activity/practice/tests/test_workflow.py | 2 +- exercises/durable-execution/practice/workflow.py | 9 ++++++--- exercises/durable-execution/solution/workflow.py | 4 ++-- requirements.txt | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/exercises/debug-activity/practice/tests/test_workflow.py b/exercises/debug-activity/practice/tests/test_workflow.py index 56b3bca..1c913da 100644 --- a/exercises/debug-activity/practice/tests/test_workflow.py +++ b/exercises/debug-activity/practice/tests/test_workflow.py @@ -58,7 +58,7 @@ async def test_failed_pizza_order_outside_delivery_error(): id="test-translation-workflow-id", task_queue="test-pizza-order", ) - assert isinstance(e.value, WorkflowFailureError) + assert isinstance(e.value.cause, ApplicationError) assert "customer lives outside the service area" == str(e.value.cause) diff --git a/exercises/durable-execution/practice/workflow.py b/exercises/durable-execution/practice/workflow.py index 6ca20f8..8502f83 100644 --- a/exercises/durable-execution/practice/workflow.py +++ b/exercises/durable-execution/practice/workflow.py @@ -17,7 +17,7 @@ class TranslationWorkflow: workflow.logger.workflow_info_on_message = False - workflow.logger.workflow_info_on_extra = False + #workflow.logger.workflow_info_on_extra = False @workflow.run async def run(self, input: TranslationWorkflowInput) -> TranslationWorkflowOutput: @@ -44,11 +44,14 @@ async def run(self, input: TranslationWorkflowInput) -> TranslationWorkflowOutpu # TODO PART D:Add a Timer that sleeps for 10 seconds + + # TODO PART A:Add a log message using the workflow logger at the debug level + # stating that the Activity has been invoked. Include the term and language code. + goodbye_input = TranslationActivityInput( language_code=input.language_code, term="goodbye" ) - # TODO PART A:Add a log message using the workflow logger at the debug level - # stating that the Activity has been invoked. Include the term and language code. + goodbye_result = await workflow.execute_activity_method( TranslationActivities.translate_term, goodbye_input, diff --git a/exercises/durable-execution/solution/workflow.py b/exercises/durable-execution/solution/workflow.py index c4398a1..7d2c7b6 100644 --- a/exercises/durable-execution/solution/workflow.py +++ b/exercises/durable-execution/solution/workflow.py @@ -17,11 +17,11 @@ class TranslationWorkflow: workflow.logger.workflow_info_on_message = False - workflow.logger.workflow_info_on_extra = False + #workflow.logger.workflow_info_on_extra = False @workflow.run async def run(self, input: TranslationWorkflowInput) -> TranslationWorkflowOutput: - workflow.logger.info(f"tTranslationWorkflow invoked with {input}") + workflow.logger.info(f"TranslationWorkflow invoked with {input}") hello_input = TranslationActivityInput( language_code=input.language_code, term="hello" diff --git a/requirements.txt b/requirements.txt index 5fecdc3..facb73f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ pluggy==1.5.0 protobuf==5.27.0 pytest==8.2.2 pytest-asyncio==0.23.7 -temporalio==1.6.0 +temporalio==1.10.0 types-protobuf==5.26.0.20240422 typing_extensions==4.12.1 Werkzeug==3.0.3