Skip to content

Commit 266b3e6

Browse files
chore: sync code snippets via snipsync (#4490)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7ebb0e1 commit 266b3e6

2 files changed

Lines changed: 47 additions & 84 deletions

File tree

docs/develop/go/best-practices/data-handling/external-storage.mdx

Lines changed: 46 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -41,58 +41,43 @@ The Go SDK includes an S3 storage driver. Follow these steps to set it up:
4141
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):
4242

4343
<!--SNIPSTART go-s3-driver-create-->
44+
[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)
45+
```go
46+
cfg, err := config.LoadDefaultConfig(context.Background(),
47+
config.WithRegion("us-east-2"),
48+
)
49+
if err != nil {
50+
log.Fatalf("load AWS config: %v", err)
51+
}
4452

45-
```go
46-
import (
47-
"github.com/aws/aws-sdk-go-v2/config"
48-
"github.com/aws/aws-sdk-go-v2/service/s3"
49-
"go.temporal.io/sdk/contrib/aws/s3driver"
50-
"go.temporal.io/sdk/contrib/aws/s3driver/awssdkv2"
51-
)
52-
53-
cfg, err := config.LoadDefaultConfig(context.Background(),
54-
config.WithRegion("us-east-2"),
55-
)
56-
if err != nil {
57-
log.Fatalf("load AWS config: %v", err)
58-
}
59-
60-
driver, err := s3driver.NewDriver(s3driver.Options{
61-
Client: awssdkv2.NewClient(s3.NewFromConfig(cfg)),
62-
Bucket: s3driver.StaticBucket("my-temporal-payloads"),
63-
})
64-
if err != nil {
65-
log.Fatalf("create S3 driver: %v", err)
66-
}
67-
```
68-
53+
driver, err := s3driver.NewDriver(s3driver.Options{
54+
Client: awssdkv2.NewClient(s3.NewFromConfig(cfg)),
55+
Bucket: s3driver.StaticBucket("my-temporal-payloads"),
56+
})
57+
if err != nil {
58+
log.Fatalf("create S3 driver: %v", err)
59+
}
60+
```
6961
<!--SNIPEND-->
7062

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

7365
<!--SNIPSTART go-s3-external-storage-setup-->
66+
[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)
67+
```go
68+
c, err := client.Dial(client.Options{
69+
HostPort: "localhost:7233",
70+
ExternalStorage: converter.ExternalStorage{
71+
Drivers: []converter.StorageDriver{driver},
72+
},
73+
})
74+
if err != nil {
75+
log.Fatalf("connect to Temporal: %v", err)
76+
}
77+
defer c.Close()
7478

75-
```go
76-
import (
77-
"go.temporal.io/sdk/client"
78-
"go.temporal.io/sdk/converter"
79-
"go.temporal.io/sdk/worker"
80-
)
81-
82-
c, err := client.Dial(client.Options{
83-
HostPort: "localhost:7233",
84-
ExternalStorage: converter.ExternalStorage{
85-
Drivers: []converter.StorageDriver{driver},
86-
},
87-
})
88-
if err != nil {
89-
log.Fatalf("connect to Temporal: %v", err)
90-
}
91-
defer c.Close()
92-
93-
w := worker.New(c, "my-task-queue", worker.Options{})
94-
```
95-
79+
w := worker.New(c, "my-task-queue", worker.Options{})
80+
```
9681
<!--SNIPEND-->
9782

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

11499
<!--SNIPSTART go-custom-storage-driver-->
115-
100+
[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)
116101
```go
117-
package main
118-
119-
import (
120-
"fmt"
121-
"os"
122-
"path/filepath"
123-
124-
"github.com/google/uuid"
125-
commonpb "go.temporal.io/api/common/v1"
126-
"go.temporal.io/sdk/converter"
127-
"google.golang.org/protobuf/proto"
128-
)
129-
130102
type LocalDiskStorageDriver struct {
131103
storeDir string
132104
}
@@ -204,7 +176,6 @@ func (d *LocalDiskStorageDriver) Retrieve(
204176
return payloads, nil
205177
}
206178
```
207-
208179
<!--SNIPEND-->
209180

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

264235
<!--SNIPSTART go-external-storage-threshold-->
265-
236+
[features/snippets/external_storage/threshold/threshold_config.go](https://github.com/temporalio/features/blob/main/features/snippets/external_storage/threshold/threshold_config.go)
266237
```go
267-
import "go.temporal.io/sdk/converter"
268-
269238
c, err := client.Dial(client.Options{
270-
ExternalStorage: converter.ExternalStorage{
271-
Drivers: []converter.StorageDriver{driver},
272-
PayloadSizeThreshold: 1,
273-
},
239+
ExternalStorage: converter.ExternalStorage{
240+
Drivers: []converter.StorageDriver{driver},
241+
PayloadSizeThreshold: 1,
242+
},
274243
})
275244
```
276-
277245
<!--SNIPEND-->
278246

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

298266
<!--SNIPSTART go-external-storage-multiple-drivers-->
299-
267+
[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)
300268
```go
301-
import (
302-
commonpb "go.temporal.io/api/common/v1"
303-
"go.temporal.io/sdk/converter"
304-
)
305-
306269
type PreferredSelector struct {
307-
preferred converter.StorageDriver
270+
preferred converter.StorageDriver
308271
}
309272

310273
func (s *PreferredSelector) SelectDriver(
311-
ctx converter.StorageDriverStoreContext,
312-
payload *commonpb.Payload,
274+
ctx converter.StorageDriverStoreContext,
275+
payload *commonpb.Payload,
313276
) (converter.StorageDriver, error) {
314-
return s.preferred, nil
277+
return s.preferred, nil
315278
}
316279

317-
// Usage:
318-
converter.ExternalStorage{
319-
Drivers: []converter.StorageDriver{preferredDriver, legacyDriver},
320-
DriverSelector: &PreferredSelector{preferred: preferredDriver},
280+
func MultipleDriversSetup(preferredDriver, legacyDriver converter.StorageDriver) converter.ExternalStorage {
281+
return converter.ExternalStorage{
282+
Drivers: []converter.StorageDriver{preferredDriver, legacyDriver},
283+
DriverSelector: &PreferredSelector{preferred: preferredDriver},
284+
}
321285
}
322286
```
323-
324287
<!--SNIPEND-->

docs/develop/python/nexus/feature-guide.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class MyNexusServiceHandler:
245245
input.name, # First argument: name
246246
input.language, # Second argument: language
247247
],
248-
id=str(uuid.uuid4()),
248+
id=f"hello-multi-args-{input.name}-{input.language}",
249249
)
250250

251251

0 commit comments

Comments
 (0)