11"""
2- This file demonstrates how to implement a Nexus service that is backed by a long-running
3- workflow and exposes operations that perform signals, updates, and queries against that
4- workflow.
2+ This file demonstrates how to implement a Nexus service that is backed by a long-running workflow
3+ and exposes operations that perform updates, and queries against that workflow.
54"""
65
76from __future__ import annotations
@@ -31,19 +30,16 @@ def __init__(
3130 async def create (cls , client : Client , task_queue : str ) -> GreetingServiceHandler :
3231 # Obtain a workflow handle to the long-running workflow that backs this service, starting
3332 # the workflow if it is not already running.
34- return cls (await cls ._get_workflow_handle (client , task_queue ))
35-
36- @staticmethod
37- async def _get_workflow_handle (
38- client : Client , task_queue : str
39- ) -> WorkflowHandle [GreetingWorkflow , str ]:
40- return await client .start_workflow (
33+ wf_handle = await client .start_workflow (
4134 GreetingWorkflow .run ,
4235 id = "nexus-sync-operations-greeting-workflow" ,
4336 task_queue = task_queue ,
4437 id_conflict_policy = WorkflowIDConflictPolicy .USE_EXISTING ,
4538 )
39+ return cls (wf_handle )
4640
41+ # 👉 This is a handler for a nexus operation whose internal implementation involves executing a
42+ # query against a long-running workflow that is private to the nexus service.
4743 @nexusrpc .handler .sync_operation
4844 async def get_languages (
4945 self , ctx : nexusrpc .handler .StartOperationContext , input : GetLanguagesInput
@@ -52,12 +48,16 @@ async def get_languages(
5248 GreetingWorkflow .get_languages , input
5349 )
5450
51+ # 👉 This is a handler for a nexus operation whose internal implementation involves executing a
52+ # query against a long-running workflow that is private to the nexus service.
5553 @nexusrpc .handler .sync_operation
5654 async def get_language (
5755 self , ctx : nexusrpc .handler .StartOperationContext , input : None
5856 ) -> Language :
5957 return await self .greeting_workflow_handle .query (GreetingWorkflow .get_language )
6058
59+ # 👉 This is a handler for a nexus operation whose internal implementation involves executing an
60+ # update against a long-running workflow that is private to the nexus service.
6161 @nexusrpc .handler .sync_operation
6262 async def set_language (
6363 self ,
0 commit comments