2121
2222@nexusrpc .handler .service_handler (service = GreetingService )
2323class GreetingServiceHandler :
24- # This nexus service is backed by a long-running "entity" workflow. This means that the workflow
25- # is always running in the background, allowing the service to be stateful and durable. The
26- # service interacts with it via messages (updates and queries). All of this is implementation
27- # detail private to the nexus handler: the nexus caller does not know how the operations are
28- # implemented or what is providing the backing storage.
29- LONG_RUNNING_WORKFLOW_ID = "nexus-sync-operations-greeting-workflow"
24+ def __init__ (self , workflow_id : str ):
25+ self .workflow_id = workflow_id
3026
3127 @classmethod
32- async def start (cls , client : Client , task_queue : str ) -> None :
28+ async def create (
29+ cls , workflow_id : str , client : Client , task_queue : str
30+ ) -> GreetingServiceHandler :
3331 # Start the long-running "entity" workflow, if it is not already running.
3432 await client .start_workflow (
3533 GreetingWorkflow .run ,
36- id = cls . LONG_RUNNING_WORKFLOW_ID ,
34+ id = workflow_id ,
3735 task_queue = task_queue ,
3836 id_conflict_policy = WorkflowIDConflictPolicy .USE_EXISTING ,
3937 )
38+ return cls (workflow_id )
4039
4140 @property
4241 def greeting_workflow_handle (self ) -> WorkflowHandle [GreetingWorkflow , str ]:
@@ -48,7 +47,7 @@ def greeting_workflow_handle(self) -> WorkflowHandle[GreetingWorkflow, str]:
4847 # long-running work in a nexus operation handler, use
4948 # temporalio.nexus.workflow_run_operation (see the hello_nexus sample).
5049 return nexus .client ().get_workflow_handle_for (
51- GreetingWorkflow .run , self .LONG_RUNNING_WORKFLOW_ID
50+ GreetingWorkflow .run , self .workflow_id
5251 )
5352
5453 # 👉 This is a handler for a nexus operation whose internal implementation involves executing a
0 commit comments