|
| 1 | +from message_passing.introduction import Language |
| 2 | +from message_passing.introduction.workflows import ( |
| 3 | + ApproveInput, |
| 4 | + GetLanguagesInput, |
| 5 | + SetLanguageInput, |
| 6 | + SetLanguageUsingActivityInput, |
| 7 | +) |
| 8 | +from temporalio import workflow |
| 9 | + |
| 10 | +with workflow.unsafe.imports_passed_through(): |
| 11 | + from nexus_sync_operations.service import GreetingService |
| 12 | + |
| 13 | +NEXUS_ENDPOINT = "nexus-sync-operations-nexus-endpoint" |
| 14 | + |
| 15 | + |
| 16 | +@workflow.defn |
| 17 | +class CallerWorkflow: |
| 18 | + @workflow.run |
| 19 | + async def run(self) -> None: |
| 20 | + nexus_client = workflow.create_nexus_client( |
| 21 | + service=GreetingService, |
| 22 | + endpoint=NEXUS_ENDPOINT, |
| 23 | + ) |
| 24 | + |
| 25 | + # Get supported languages |
| 26 | + supported_languages = await nexus_client.execute_operation( |
| 27 | + GreetingService.get_languages, GetLanguagesInput(include_unsupported=False) |
| 28 | + ) |
| 29 | + print(f"supported languages: {supported_languages}") |
| 30 | + |
| 31 | + # Set language |
| 32 | + 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), |
| 45 | + ) |
| 46 | + assert ( |
| 47 | + await nexus_client.execute_operation(GreetingService.get_language, None) |
| 48 | + == Language.ARABIC |
| 49 | + ) |
| 50 | + print(f"language changed: {previous_language.name} -> {Language.ARABIC.name}") |
| 51 | + |
| 52 | + # Approve |
| 53 | + await nexus_client.execute_operation( |
| 54 | + GreetingService.approve, ApproveInput(name="") |
| 55 | + ) |
0 commit comments