Skip to content

Commit 5afcfc0

Browse files
committed
Only call one of the set_language operations
1 parent f4c6d32 commit 5afcfc0

4 files changed

Lines changed: 4 additions & 46 deletions

File tree

nexus_sync_operations/caller/workflows.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from message_passing.introduction.workflows import (
55
GetLanguagesInput,
66
SetLanguageInput,
7-
SetLanguageUsingActivityInput,
87
)
98

109
with workflow.unsafe.imports_passed_through():
@@ -30,18 +29,8 @@ async def run(self) -> None:
3029

3130
# Set language
3231
previous_language = await nexus_client.execute_operation(
33-
GreetingService.set_language, SetLanguageInput(language=Language.CHINESE)
34-
)
35-
assert (
36-
await nexus_client.execute_operation(GreetingService.get_language, None)
37-
== Language.CHINESE
38-
)
39-
print(f"language changed: {previous_language.name} -> {Language.CHINESE.name}")
40-
41-
# Set language using remote service
42-
previous_language = await nexus_client.execute_operation(
43-
GreetingService.set_language_using_activity,
44-
SetLanguageUsingActivityInput(language=Language.ARABIC),
32+
GreetingService.set_language,
33+
SetLanguageInput(language=Language.ARABIC),
4534
)
4635
assert (
4736
await nexus_client.execute_operation(GreetingService.get_language, None)

nexus_sync_operations/handler/service_handler.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
GetLanguagesInput,
1616
GreetingWorkflow,
1717
SetLanguageInput,
18-
SetLanguageUsingActivityInput,
1918
)
2019
from nexus_sync_operations.service import GreetingService
2120

@@ -61,18 +60,10 @@ async def get_language(
6160

6261
@nexusrpc.handler.sync_operation
6362
async def set_language(
64-
self, ctx: nexusrpc.handler.StartOperationContext, input: SetLanguageInput
65-
) -> Language:
66-
return await self.greeting_workflow_handle.execute_update(
67-
GreetingWorkflow.set_language, input.language
68-
)
69-
70-
@nexusrpc.handler.sync_operation
71-
async def set_language_using_activity(
7263
self,
7364
ctx: nexusrpc.handler.StartOperationContext,
74-
input: SetLanguageUsingActivityInput,
65+
input: SetLanguageInput,
7566
) -> Language:
7667
return await self.greeting_workflow_handle.execute_update(
77-
GreetingWorkflow.set_language_using_activity, input.language
68+
GreetingWorkflow.set_language_using_activity, input
7869
)

nexus_sync_operations/service.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from message_passing.introduction.workflows import (
55
GetLanguagesInput,
66
SetLanguageInput,
7-
SetLanguageUsingActivityInput,
87
)
98

109

@@ -13,6 +12,3 @@ class GreetingService:
1312
get_languages: nexusrpc.Operation[GetLanguagesInput, list[Language]]
1413
get_language: nexusrpc.Operation[None, Language]
1514
set_language: nexusrpc.Operation[SetLanguageInput, Language]
16-
set_language_using_activity: nexusrpc.Operation[
17-
SetLanguageUsingActivityInput, Language
18-
]

tests/nexus_sync_operations/nexus_sync_operations_test.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import sys
32

43
import pytest
54
from temporalio.client import Client
@@ -15,9 +14,6 @@ async def test_nexus_sync_operations(client: Client, env: WorkflowEnvironment):
1514
if env.supports_time_skipping:
1615
pytest.skip("Nexus tests don't work under the Java test server")
1716

18-
if sys.version_info[:2] < (3, 10):
19-
pytest.skip("Sample is written for Python >= 3.10")
20-
2117
create_response = await create_nexus_endpoint(
2218
name=nexus_sync_operations.caller.workflows.NEXUS_ENDPOINT,
2319
task_queue=nexus_sync_operations.handler.worker.TASK_QUEUE,
@@ -29,26 +25,12 @@ async def test_nexus_sync_operations(client: Client, env: WorkflowEnvironment):
2925
client,
3026
)
3127
)
32-
# Give worker time to start the long-running workflow
33-
await asyncio.sleep(1)
34-
35-
# Execute the caller workflow which will test all the Nexus operations
3628
await nexus_sync_operations.caller.app.execute_caller_workflow(
3729
client,
3830
)
39-
40-
# Clean up the handler worker
4131
nexus_sync_operations.handler.worker.interrupt_event.set()
4232
await handler_worker_task
4333
nexus_sync_operations.handler.worker.interrupt_event.clear()
44-
45-
# The test passes if the caller workflow completes successfully
46-
# The caller workflow verifies that:
47-
# - get_languages returns supported languages
48-
# - set_language updates the language and returns the previous one
49-
# - get_language returns the current language
50-
# - set_language_using_activity updates the language using an activity
51-
# - approve sends the signal successfully
5234
finally:
5335
await delete_nexus_endpoint(
5436
id=create_response.endpoint.id,

0 commit comments

Comments
 (0)