Skip to content

Commit b8a308b

Browse files
dandavisonjsundaibrianmacdonald-temporal
authored
Document nexus.client() and nexus.info() in Python nexus docs (#3873)
* Document nexus.client() in Python nexus docs * Update capitalization --------- Co-authored-by: Jwahir Sundai <[email protected]> Co-authored-by: Brian MacDonald <[email protected]>
1 parent 1b96cb8 commit b8a308b

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

docs/develop/python/temporal-nexus.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ The `nexusrpc.handler` and `temporalio.nexus` modules have utilities to help cre
139139
### Develop a Synchronous Nexus Operation handler
140140

141141
The `@nexusrpc.handler.sync_operation` decorator is for exposing simple RPC handlers.
142-
Its handler function can access an SDK client that can be used for signaling, querying, and listing Workflows.
143-
However, implementations are free to make arbitrary calls to other services or databases, or perform computations such as this one:
144142

145143
[hello_nexus/handler/service_handler.py](https://github.com/temporalio/samples-python/blob/main/hello_nexus/handler/service_handler.py)
146144

@@ -156,6 +154,33 @@ class MyNexusServiceHandler:
156154
return MyOutput(message=f"Hello {input.name} from sync operation!")
157155
```
158156

157+
158+
A synchronous operation handler must return quickly (less than `10s`).
159+
In addition to performing simple CPU-bound computations such as the one above, implementations are free to make arbitrary calls to other services or databases.
160+
The handler function can access an SDK client that can be used to execute Signals, Updates, or Queries against a Workflow, or to do other client operations such as listing Workflows.
161+
The [nexus_sync_operations](https://github.com/temporalio/samples-python/blob/main/nexus_sync_operations) shows how to create a Nexus Service uses synchronous operations to send Updates and Queries:
162+
163+
[nexus_sync_operations/handler/service_handler.py](https://github.com/temporalio/samples-python/blob/main/nexus_sync_operations/handler/service_handler.py)
164+
165+
166+
```python
167+
from temporalio import nexus
168+
169+
@nexusrpc.handler.service_handler(service=GreetingService)
170+
class GreetingServiceHandler:
171+
172+
@property
173+
def greeting_workflow_handle(self) -> WorkflowHandle[GreetingWorkflow, str]:
174+
return nexus.client().get_workflow_handle_for(
175+
GreetingWorkflow.run, self.workflow_id
176+
)
177+
178+
...
179+
```
180+
181+
In addition to `nexus.client()`, you can use `nexus.info()` to access information about the currently-executing Nexus Operation including its Task Queue.
182+
183+
159184
### Develop an Asynchronous Nexus Operation handler to start a Workflow
160185

161186
Use the `@nexus.workflow_run_operation` decorator, which is the easiest way to expose a Workflow as an operation.

0 commit comments

Comments
 (0)