Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/develop/go/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ From there, you can dive deeper into any of the Temporal primitives to start bui

- [Quickstart](/develop/go/nexus/quickstart)
- [Feature guide](/develop/go/nexus/feature-guide)
- [Standalone Operations](/develop/go/nexus/standalone-operations)

## [Platform](/develop/go/platform)

Expand Down
1 change: 1 addition & 0 deletions docs/develop/go/nexus/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Temporal Go SDK support for Nexus is [Generally Available](/evaluate/development

- [Quickstart](/develop/go/nexus/quickstart)
- [Feature guide](/develop/go/nexus/feature-guide)
- [Standalone Operations](/develop/go/nexus/standalone-operations)
164 changes: 164 additions & 0 deletions docs/develop/go/nexus/standalone-operations.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
id: standalone-operations
title: Standalone Nexus Operations - Go SDK
sidebar_label: Standalone Operations
toc_max_heading_level: 4
keywords:
- standalone nexus operation
- nexus operation execution
- execute nexus operation
- nexus operation handle
- list nexus operations
- count nexus operations
- go sdk
tags:
- Nexus
- Temporal Client
- Go SDK
- Temporal SDKs
description: Execute Nexus Operations independently without a Workflow using the Temporal Go SDK.
---

:::tip SUPPORT, STABILITY, and DEPENDENCY INFO

Temporal Go SDK support for Standalone Nexus Operations is at
[Pre-release](/evaluate/development-production-features/release-stages#pre-release).

All APIs are experimental and may be subject to backwards-incompatible changes.

:::

[Standalone Nexus Operations](/standalone-nexus-operation) let you run Nexus Operation Executions independently, without
being orchestrated by a Workflow. Instead of calling a Nexus Operation from within a Workflow Definition using
`workflow.NewNexusClient()`, you execute a Standalone Nexus Operation directly from a Nexus Client created using
`client.NewNexusClient()`.

Standalone Nexus Operations use the same Nexus Service contract, Operation handlers, and Worker setup as
Workflow-driven Operations — only the execution path differs. See the [Nexus feature guide](/develop/go/nexus/feature-guide) for details on
[defining a Service contract](/develop/go/nexus/feature-guide#define-nexus-service-contract),
[developing Operation handlers](/develop/go/nexus/feature-guide#develop-nexus-service-operation-handlers), and
[registering a Service in a Worker](/develop/go/nexus/feature-guide#register-a-nexus-service-in-a-worker).
Comment on lines +37 to +40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn here on if we should suggest the quickstart or the feature guide here. I think either are fine, but maybe the quickstart would be nicer if someone has no idea about Nexus.


This page focuses on the client-side APIs that are unique to Standalone Nexus Operations:

- [Execute a Standalone Nexus Operation](#execute-operation)
- [Get the result of a Standalone Nexus Operation](#get-operation-result)
- [List Standalone Nexus Operations](#list-operations)
- [Count Standalone Nexus Operations](#count-operations)
- [Run Standalone Nexus Operations with Temporal Cloud](#run-standalone-nexus-operations-temporal-cloud)

Comment thread
jsundai marked this conversation as resolved.
:::note

This documentation uses source code from
[nexus-standalone-operations](https://github.com/temporalio/samples-go/tree/main/nexus-standalone-operations).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the sample ready to merge? temporalio/samples-go#456 @Quinn-With-Two-Ns


:::

## Execute a Standalone Nexus Operation {/* #execute-operation */}

To execute a Standalone Nexus Operation, first create a
[`NexusClient`](https://pkg.go.dev/go.temporal.io/sdk/client#NexusClient) using `client.NewNexusClient()`, bound to a
specific Nexus Endpoint and Service. The endpoint must be pre-created on the server. Then call `ExecuteOperation()` from
application code (for example, a starter program), not from inside a Workflow Definition.

`ExecuteOperation` returns a [`NexusOperationHandle`](https://pkg.go.dev/go.temporal.io/sdk/client#NexusOperationHandle)
that you can use to get the result of the Operation.
[`StartNexusOperationOptions`](https://pkg.go.dev/go.temporal.io/sdk/client#StartNexusOperationOptions) requires `ID`.
`ScheduleToCloseTimeout` is optional and defaults to the maximum allowed by the Temporal server.

```go
nexusClient, err := c.NewNexusClient(client.NexusClientOptions{
Endpoint: "my-nexus-endpoint",
Service: "my-service-name",
})

handle, err := nexusClient.ExecuteOperation(ctx, operationName, input, client.StartNexusOperationOptions{
ID: "unique-operation-id",
ScheduleToCloseTimeout: 10 * time.Second,
})
```

See the full
[starter sample](https://github.com/temporalio/samples-go/blob/main/nexus-standalone-operations/starter/main.go)
for a complete example that executes both synchronous and asynchronous Operations, gets their results, and lists and
counts Operations.

To run the starter (in a separate terminal from the Worker):

```
go run nexus-standalone-operations/starter/main.go
```

## Get the result of a Standalone Nexus Operation {/* #get-operation-result */}

Use `NexusOperationHandle.Get()` to block until the Operation completes and retrieve its result. This works for both
synchronous and asynchronous (Workflow-backed) Operations.

```go
var result service.EchoOutput
err = handle.Get(context.Background(), &result)
if err != nil {
log.Fatalln("Operation failed", err)
}
log.Println("Operation result:", result.Message)
```

If the Operation completed successfully, the result is deserialized into the provided pointer. If the Operation failed,
the failure is returned as an error.

## List Standalone Nexus Operations {/* #list-operations */}

Use [`client.ListNexusOperations()`](https://pkg.go.dev/go.temporal.io/sdk/client#Client) to list Standalone Nexus
Operation Executions that match a [List Filter](/list-filter) query. The result contains an iterator that yields
operation metadata entries.

Note that `ListNexusOperations` is called on the base `client.Client`, not on the `NexusClient`.

```go
resp, err := c.ListNexusOperations(context.Background(), client.ListNexusOperationsOptions{
Query: "Endpoint = 'my-nexus-endpoint'",
})
if err != nil {
log.Fatalln("Unable to list Nexus operations", err)
}

for metadata, err := range resp.Results {
if err != nil {
log.Fatalln("Error iterating operations", err)
}
log.Printf("OperationID: %s, Operation: %s, Status: %v\n",
metadata.OperationID, metadata.Operation, metadata.Status)
}
```

The `Query` field accepts [List Filter](/list-filter) syntax. For example,
`"Endpoint = 'my-endpoint' AND Status = 'Running'"`.

## Count Standalone Nexus Operations {/* #count-operations */}

Use [`client.CountNexusOperations()`](https://pkg.go.dev/go.temporal.io/sdk/client#Client) to count Standalone Nexus
Operation Executions that match a [List Filter](/list-filter) query.

Note that `CountNexusOperations` is called on the base `client.Client`, not on the `NexusClient`.

```go
resp, err := c.CountNexusOperations(context.Background(), client.CountNexusOperationsOptions{
Query: "Endpoint = 'my-nexus-endpoint'",
})
if err != nil {
log.Fatalln("Unable to count Nexus operations", err)
}

log.Println("Total Nexus operations:", resp.Count)
```

## Run Standalone Nexus Operations with Temporal Cloud {/* #run-standalone-nexus-operations-temporal-cloud */}

The code samples on this page use `envconfig.MustLoadDefaultClientOptions()`, so the same code
works against Temporal Cloud — just configure the connection via environment variables or a TOML
profile. No code changes are needed.

For full details on connecting to Temporal Cloud, including Namespace creation, Nexus Endpoint
setup, certificate generation, and authentication options, see
[Make Nexus calls across Namespaces in Temporal Cloud](/develop/go/nexus/feature-guide#nexus-calls-across-namespaces-temporal-cloud)
and [Connect to Temporal Cloud](/develop/go/client/temporal-client#connect-to-temporal-cloud).
1 change: 1 addition & 0 deletions docs/develop/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ From there, you can dive deeper into any of the Temporal primitives to start bui

- [Quickstart](/develop/python/nexus/quickstart)
- [Feature guide](/develop/python/nexus/feature-guide)
- [Standalone Operations](/develop/python/nexus/standalone-operations)

## [Platform](/develop/python/platform)

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/python/nexus/feature-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class MyNexusServiceHandler:
<!--SNIPEND-->


### Register your Nexus Service handler in a Worker
### Register your Nexus Service handler in a Worker {/* #register-a-nexus-service-in-a-worker */}

After developing an asynchronous Nexus Operation handler to start a Workflow, the next step is to register your Nexus Service handler in a Worker.
At this stage you can pass any arguments you need to your service handler's `__init__` method.
Expand Down
1 change: 1 addition & 0 deletions docs/develop/python/nexus/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Temporal Python SDK support for Nexus is [Generally Available](/evaluate/develop

- [Quickstart](/develop/python/nexus/quickstart)
- [Feature guide](/develop/python/nexus/feature-guide)
- [Standalone Operations](/develop/python/nexus/standalone-operations)
153 changes: 153 additions & 0 deletions docs/develop/python/nexus/standalone-operations.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
id: standalone-operations
title: Standalone Nexus Operations - Python SDK
sidebar_label: Standalone Operations
toc_max_heading_level: 4
keywords:
- standalone nexus operation
- nexus operation execution
- execute nexus operation
- nexus operation handle
- list nexus operations
- count nexus operations
- python sdk
tags:
- Nexus
- Temporal Client
- Python SDK
- Temporal SDKs
description: Execute Nexus Operations independently without a Workflow using the Temporal Python SDK.
---

:::tip SUPPORT, STABILITY, and DEPENDENCY INFO

Temporal Python SDK support for Standalone Nexus Operations is at
[Pre-release](/evaluate/development-production-features/release-stages#pre-release).

All APIs are experimental and may be subject to backwards-incompatible changes.

:::

[Standalone Nexus Operations](/standalone-nexus-operation) let you run Nexus Operation Executions independently, without
being orchestrated by a Workflow. Instead of calling a Nexus Operation from within a Workflow Definition using
`workflow.create_nexus_client()`, you execute a Standalone Nexus Operation directly from a Nexus Client created using
`client.create_nexus_client()`.

Standalone Nexus Operations use the same Nexus Service contract, Operation handlers, and Worker setup as
Workflow-driven Operations — only the execution path differs. See the [Nexus feature guide](/develop/python/nexus/feature-guide) for details on
[defining a Service contract](/develop/python/nexus/feature-guide#define-nexus-service-contract),
[developing Operation handlers](/develop/python/nexus/feature-guide#develop-nexus-service-operation-handlers), and
[registering a Service in a Worker](/develop/python/nexus/feature-guide#register-a-nexus-service-in-a-worker).

This page focuses on the client-side APIs that are unique to Standalone Nexus Operations:

- [Execute a Standalone Nexus Operation](#execute-operation)
- [Start a Standalone Nexus Operation and Wait for the Result](#get-operation-result)
- [List Standalone Nexus Operations](#list-operations)
- [Count Standalone Nexus Operations](#count-operations)
- [Run Standalone Nexus Operations with Temporal Cloud](#run-standalone-nexus-operations-temporal-cloud)

:::note

This documentation uses source code from
[nexus-standalone-operations](https://github.com/temporalio/samples-python/tree/main/nexus-standalone-operations).

:::

## Execute a Standalone Nexus Operation {/* #execute-operation */}

To execute a Standalone Nexus Operation, first create a
[`NexusClient`](https://python.temporal.io/temporalio.client.NexusClient.html) using `client.create_nexus_client()`, bound to a
specific Nexus Endpoint and Service. The endpoint must be pre-created on the server. Then call `start_operation()` or `execute_operation()` from application code (for example, a starter program), not from inside a Workflow Definition.

`execute_operation` waits for the Operation to complete and returns the result.
Both methods require `id`. `schedule_to_close_timeout` is optional and defaults to the maximum allowed by the Temporal server.

```python
nexus_client = client.create_nexus_client(
service=MyNexusService, endpoint=ENDPOINT_NAME
)

# Await the result of the operation immediately.
echo_result = await nexus_client.execute_operation(
MyNexusService.echo,
EchoInput(message="hello"),
id=f"echo-{uuid.uuid4()}",
schedule_to_close_timeout=timedelta(seconds=10),
)
```

See the full
[starter sample](https://github.com/temporalio/samples-python/blob/main/nexus_standalone_operations/starter.py)
for a complete example that executes both synchronous and asynchronous Operations, gets their results, and lists and
counts Operations.

## Start a Standalone Nexus Operation and Wait for the Result {/* #get-operation-result */}

`start_operation` returns a [`NexusOperationHandle`](https://python.temporal.io/temporalio.client.NexusOperationHandle.html).
Use `NexusOperationHandle.result()` to wait until the Operation completes and retrieve its result. This works for both
synchronous and asynchronous Operations.

```python
# Start an operation and get a NexusOperationHandle
handle = await nexus_client.start_operation(
MyNexusService.hello,
HelloInput(name="World"),
id=f"hello-{uuid.uuid4()}",
schedule_to_close_timeout=timedelta(seconds=10),
)
# Await the result
try:
hello_result = await handle.result()
print(hello_result)
except err:
print(err)
raise
```

If the Operation completed successfully, the result is returned. If the Operation failed, the failure is raised as an error.

## List Standalone Nexus Operations {/* #list-operations */}

Use [`client.list_nexus_operations()`](https://python.temporal.io/temporalio.client.Client.html#list_nexus_operations) to list Standalone Nexus
Operation Executions that match a [List Filter](/list-filter) query. The result contains an iterator that yields
operation metadata entries.

Note that `list_nexus_operations` is called on the base `client.Client`, not on the `NexusClient`.

```python
query = f'Endpoint = "{ENDPOINT_NAME}"'
async for op in client.list_nexus_operations(query):
print(
f" OperationId: {op.operation_id},",
f" Operation: {op.operation},",
f" Status: {op.status.name}",
)
```

The `query` parameter accepts [List Filter](/list-filter) syntax. For example,
`"Endpoint = 'my-endpoint' AND Status = 'Running'"`.

## Count Standalone Nexus Operations {/* #count-operations */}

Use [`client.count_nexus_operations()`](https://python.temporal.io/temporalio.client.Client.html#count_nexus_operations) to count Standalone Nexus
Operation Executions that match a [List Filter](/list-filter) query.

Note that `count_nexus_operations` is called on the base `client.Client`, not on the `NexusClient`.

```python
query = f'Endpoint = "{ENDPOINT_NAME}"'
count = await client.count_nexus_operations(query)
print(f"Total Nexus operations: {count.count}")
```

## Run Standalone Nexus Operations with Temporal Cloud {/* #run-standalone-nexus-operations-temporal-cloud */}

The code samples referenced on this page use [`ClientConfig.load_client_connect_config()`](https://python.temporal.io/temporalio.envconfig.ClientConfig.html#load_client_connect_config), so the same code
works against Temporal Cloud — just configure the connection via environment variables or a TOML
profile. No code changes are needed.

For full details on connecting to Temporal Cloud, including Namespace creation, Nexus Endpoint
setup, certificate generation, and authentication options, see
[Make Nexus calls across Namespaces in Temporal Cloud](/develop/python/nexus/feature-guide#nexus-calls-across-namespaces-temporal-cloud)
and [Connect to Temporal Cloud](/develop/python/client/temporal-client#connect-to-temporal-cloud).
1 change: 1 addition & 0 deletions docs/develop/typescript/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Once your local Temporal Service is set up, continue building with the following

- [Quickstart](/develop/typescript/nexus/quickstart)
- [Feature guide](/develop/typescript/nexus/feature-guide)
- [Standalone Operations](/develop/typescript/nexus/standalone-operations)

## [Platform](/develop/typescript/platform)

Expand Down
1 change: 1 addition & 0 deletions docs/develop/typescript/nexus/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ Temporal TypeScript SDK support for Nexus is in [Public Preview](/evaluate/devel

- [Quickstart](/develop/typescript/nexus/quickstart)
- [Feature guide](/develop/typescript/nexus/feature-guide)
- [Standalone Operations](/develop/typescript/nexus/standalone-operations)
Loading