Skip to content
Merged
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
129 changes: 46 additions & 83 deletions docs/develop/go/best-practices/data-handling/external-storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,58 +41,43 @@ The Go SDK includes an S3 storage driver. Follow these steps to set it up:
1. Load your AWS configuration and create the S3 storage driver. The driver uses your standard [AWS credentials](https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-gosdk.html) from the environment (environment variables, IAM role, or AWS config file):

<!--SNIPSTART go-s3-driver-create-->
[features/snippets/external_storage/s3_setup/s3_driver_create.go](https://github.com/temporalio/features/blob/main/features/snippets/external_storage/s3_setup/s3_driver_create.go)
```go
cfg, err := config.LoadDefaultConfig(context.Background(),
config.WithRegion("us-east-2"),
)
if err != nil {
log.Fatalf("load AWS config: %v", err)
}

```go
import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"go.temporal.io/sdk/contrib/aws/s3driver"
"go.temporal.io/sdk/contrib/aws/s3driver/awssdkv2"
)

cfg, err := config.LoadDefaultConfig(context.Background(),
config.WithRegion("us-east-2"),
)
if err != nil {
log.Fatalf("load AWS config: %v", err)
}

driver, err := s3driver.NewDriver(s3driver.Options{
Client: awssdkv2.NewClient(s3.NewFromConfig(cfg)),
Bucket: s3driver.StaticBucket("my-temporal-payloads"),
})
if err != nil {
log.Fatalf("create S3 driver: %v", err)
}
```

driver, err := s3driver.NewDriver(s3driver.Options{
Client: awssdkv2.NewClient(s3.NewFromConfig(cfg)),
Bucket: s3driver.StaticBucket("my-temporal-payloads"),
})
if err != nil {
log.Fatalf("create S3 driver: %v", err)
}
```
<!--SNIPEND-->

2. Configure the driver on `ExternalStorage` and pass it in your Client options:

<!--SNIPSTART go-s3-external-storage-setup-->
[features/snippets/external_storage/s3_setup/s3_external_storage_setup.go](https://github.com/temporalio/features/blob/main/features/snippets/external_storage/s3_setup/s3_external_storage_setup.go)
```go
c, err := client.Dial(client.Options{
HostPort: "localhost:7233",
ExternalStorage: converter.ExternalStorage{
Drivers: []converter.StorageDriver{driver},
},
})
if err != nil {
log.Fatalf("connect to Temporal: %v", err)
}
defer c.Close()

```go
import (
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/converter"
"go.temporal.io/sdk/worker"
)

c, err := client.Dial(client.Options{
HostPort: "localhost:7233",
ExternalStorage: converter.ExternalStorage{
Drivers: []converter.StorageDriver{driver},
},
})
if err != nil {
log.Fatalf("connect to Temporal: %v", err)
}
defer c.Close()

w := worker.New(c, "my-task-queue", worker.Options{})
```

w := worker.New(c, "my-task-queue", worker.Options{})
```
<!--SNIPEND-->

By default, payloads larger than 256 KiB are offloaded to external storage. You can adjust this with the
Expand All @@ -112,21 +97,8 @@ The following example shows a custom driver that uses local disk as the backing
development and testing only. In production, use a durable storage system that is accessible to all Workers:

<!--SNIPSTART go-custom-storage-driver-->

[features/snippets/external_storage/custom_driver/custom_storage_driver.go](https://github.com/temporalio/features/blob/main/features/snippets/external_storage/custom_driver/custom_storage_driver.go)
```go
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/google/uuid"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/sdk/converter"
"google.golang.org/protobuf/proto"
)

type LocalDiskStorageDriver struct {
storeDir string
}
Expand Down Expand Up @@ -204,7 +176,6 @@ func (d *LocalDiskStorageDriver) Retrieve(
return payloads, nil
}
```

<!--SNIPEND-->

The following sections walk through the key parts of the driver implementation.
Expand Down Expand Up @@ -262,18 +233,15 @@ are offloaded to external storage. You can adjust this with the `PayloadSizeThre
externalize all payloads regardless of size. A value of 0 is interpreted as the default (256 KiB).

<!--SNIPSTART go-external-storage-threshold-->

[features/snippets/external_storage/threshold/threshold_config.go](https://github.com/temporalio/features/blob/main/features/snippets/external_storage/threshold/threshold_config.go)
```go
import "go.temporal.io/sdk/converter"

c, err := client.Dial(client.Options{
ExternalStorage: converter.ExternalStorage{
Drivers: []converter.StorageDriver{driver},
PayloadSizeThreshold: 1,
},
ExternalStorage: converter.ExternalStorage{
Drivers: []converter.StorageDriver{driver},
PayloadSizeThreshold: 1,
},
})
```

<!--SNIPEND-->

## Use multiple storage drivers
Expand All @@ -296,29 +264,24 @@ The following example registers two drivers but always selects `preferredDriver`
is only registered so the Worker can retrieve payloads that were previously stored with it:

<!--SNIPSTART go-external-storage-multiple-drivers-->

[features/snippets/external_storage/multiple_drivers/multiple_drivers.go](https://github.com/temporalio/features/blob/main/features/snippets/external_storage/multiple_drivers/multiple_drivers.go)
```go
import (
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/sdk/converter"
)

type PreferredSelector struct {
preferred converter.StorageDriver
preferred converter.StorageDriver
}

func (s *PreferredSelector) SelectDriver(
ctx converter.StorageDriverStoreContext,
payload *commonpb.Payload,
ctx converter.StorageDriverStoreContext,
payload *commonpb.Payload,
) (converter.StorageDriver, error) {
return s.preferred, nil
return s.preferred, nil
}

// Usage:
converter.ExternalStorage{
Drivers: []converter.StorageDriver{preferredDriver, legacyDriver},
DriverSelector: &PreferredSelector{preferred: preferredDriver},
func MultipleDriversSetup(preferredDriver, legacyDriver converter.StorageDriver) converter.ExternalStorage {
return converter.ExternalStorage{
Drivers: []converter.StorageDriver{preferredDriver, legacyDriver},
DriverSelector: &PreferredSelector{preferred: preferredDriver},
}
}
```

<!--SNIPEND-->
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 @@ -245,7 +245,7 @@ class MyNexusServiceHandler:
input.name, # First argument: name
input.language, # Second argument: language
],
id=str(uuid.uuid4()),
id=f"hello-multi-args-{input.name}-{input.language}",
)


Expand Down
Loading