Skip to content

Commit e24ec96

Browse files
committed
Add getting a handle and result of an existing operation
1 parent 93efd2f commit e24ec96

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

nexus_standalone_operations/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ uv run nexus_standalone_operations/starter.py
5353

5454
```
5555
Echo result: hello
56+
Echo result from existing operation handle: hello
5657
5758
Started `MyNexusService.Hello`. OperationID: hello-...
5859
`MyNexusService.Hello` result: Hello, World!

nexus_standalone_operations/starter.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from nexus_standalone_operations.service import (
1616
EchoInput,
17+
EchoOutput,
1718
HelloInput,
1819
MyNexusService,
1920
)
@@ -33,14 +34,22 @@ async def main() -> None:
3334
)
3435

3536
# Start sync echo operation and await the result immediately.
37+
operation_id = f"echo-{uuid.uuid4()}"
3638
echo_result = await nexus_client.execute_operation(
3739
MyNexusService.echo,
3840
EchoInput(message="hello"),
39-
id=f"echo-{uuid.uuid4()}",
41+
id=operation_id,
4042
schedule_to_close_timeout=timedelta(seconds=10),
4143
)
4244
print(f"Echo result: {echo_result.message}")
4345

46+
# Get a handle and the result of an existing operation
47+
existing_op_handle = client.get_nexus_operation_handle(
48+
operation_id, operation=MyNexusService.echo
49+
)
50+
existing_result = await existing_op_handle.result()
51+
print(f"Echo result from existing operation handle: {existing_result.message}")
52+
4453
# Start async (workflow-backed) hello operation and get a NexusOperationHandle.
4554
handle = await nexus_client.start_operation(
4655
MyNexusService.hello,

0 commit comments

Comments
 (0)