Skip to content

Commit

Permalink
feat: adds xns proto options for specifying defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
cludden committed Dec 26, 2023
1 parent c041e56 commit 4987b47
Show file tree
Hide file tree
Showing 23 changed files with 2,309 additions and 760 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ The generated code includes resources that are compatible with the Temporal Go S
*__Experimental__*
This plugin provides experimental support for cross-namespace and/or cross-cluster integration by enabling the `enable-xns` plugin option. When enabled, the plugin will generate an additional `path/to/generated/code/<package>xns` go package containing types, methods, and helpers for calling workflows, queries, signals, and updates from other Temporal workflows via activities. The activities use [heartbeating](https://docs.temporal.io/activities#activity-heartbeat) to maintain liveness for long-running workflows or updates, and their associated timeouts can be configured using the generated options helpers. For an example of xns integration, see the [example/external](./example/external/external.go) package.
This plugin provides experimental support for cross-namespace and/or cross-cluster integration by enabling the `enable-xns` plugin option. When enabled, the plugin will generate an additional `path/to/generated/code/<package>xns` go package containing types, methods, and helpers for calling workflows, queries, signals, and updates from other Temporal workflows via activities. The activities use [heartbeating](https://docs.temporal.io/activities#activity-heartbeat) to maintain liveness for long-running workflows or updates, and their associated timeouts can be configured using the generated options helpers. For an example of xns integration, see the [example/external](./example/external) package.
## Documentation
Expand Down
30 changes: 30 additions & 0 deletions docs/api/temporal/v1/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [WorkflowOptions.Query](#temporal-v1-WorkflowOptions-Query)
- [WorkflowOptions.Signal](#temporal-v1-WorkflowOptions-Signal)
- [WorkflowOptions.Update](#temporal-v1-WorkflowOptions-Update)
- [XNSActivityOptions](#temporal-v1-XNSActivityOptions)

- [CLIFeature](#temporal-v1-CLIFeature)
- [IDReusePolicy](#temporal-v1-IDReusePolicy)
Expand Down Expand Up @@ -104,6 +105,7 @@ available query configuration options
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | Fully-qualified query name |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |



Expand Down Expand Up @@ -156,6 +158,7 @@ available signal configuration options
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | Fully-qualified signal name |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |



Expand All @@ -175,6 +178,7 @@ available update configuration options
| name | [string](#string) | | Fully-qualified update name |
| validate | [bool](#bool) | | Include validation hook |
| wait_policy | [WaitPolicy](#temporal-v1-WaitPolicy) | | Default wait policy if not specified |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |



Expand Down Expand Up @@ -205,6 +209,7 @@ available workflow configuration options
| task_queue | [string](#string) | | Override service task queeu |
| task_timeout | [google.protobuf.Duration](#google-protobuf-Duration) | | The timeout for processing workflow task from the time the worker pulled this task. If a workflow task is lost, it is retried after this timeout. The resolution is seconds. |
| wait_for_cancellation | [bool](#bool) | | WaitForCancellation specifies whether to wait for canceled child workflow to be ended (child workflow can be ended as: completed/failed/timedout/terminated/canceled) |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |



Expand All @@ -220,6 +225,7 @@ Query identifies a query supported by the worklow
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ref | [string](#string) | | Query name |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |



Expand All @@ -236,6 +242,7 @@ Signal identifies a signal supported by the workflow
| ----- | ---- | ----- | ----------- |
| ref | [string](#string) | | Signal name |
| start | [bool](#bool) | | Include convenience method for signal with start |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |



Expand All @@ -251,6 +258,29 @@ Update identifies an update supported by the workflow
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ref | [string](#string) | | Update name |
| xns | [XNSActivityOptions](#temporal-v1-XNSActivityOptions) | | XNS can be used to configure default activity options for xns workflow executions |






<a name="temporal-v1-XNSActivityOptions"></a>

### XNSActivityOptions



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | Fully-qualified xns activity name |
| task_queue | [string](#string) | | Override default task queue for activity |
| schedule_to_close_timeout | [google.protobuf.Duration](#google-protobuf-Duration) | | Total time that a workflow is willing to wait for Activity to complete |
| schedule_to_start_timeout | [google.protobuf.Duration](#google-protobuf-Duration) | | Time that the Activity Task can stay in the Task Queue before it is picked up by a Worker |
| start_to_close_timeout | [google.protobuf.Duration](#google-protobuf-Duration) | | Maximum time of a single Activity execution attempt |
| heartbeat_interval | [google.protobuf.Duration](#google-protobuf-Duration) | | HeartbeatInterval configures the default heartbeat interval |
| heartbeat_timeout | [google.protobuf.Duration](#google-protobuf-Duration) | | Heartbeat timeout. Activity must call Activity.RecordHeartbeat(ctx, &#34;my-heartbeat&#34;) |
| retry_policy | [RetryPolicy](#temporal-v1-RetryPolicy) | | Specifies how to retry an Activity if an error occurs |



Expand Down
2 changes: 2 additions & 0 deletions docs/api/temporal/xns/v1/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ QueryRequest can be used to configure xns query activities
| run_id | [string](#string) | | |
| workflow_id | [string](#string) | | |
| request | [google.protobuf.Any](#google-protobuf-Any) | | |
| heartbeat_interval | [google.protobuf.Duration](#google-protobuf-Duration) | | |



Expand Down Expand Up @@ -74,6 +75,7 @@ SignalRequest can be used to configure xns signal activities
| run_id | [string](#string) | | |
| workflow_id | [string](#string) | | |
| request | [google.protobuf.Any](#google-protobuf-Any) | | |
| heartbeat_interval | [google.protobuf.Duration](#google-protobuf-Duration) | | |



Expand Down
36 changes: 36 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# example protoc-gen-go-temporal usage

In an initial terminal:
1. Start temporal
```shell
temporal server start-dev --dynamic-config-value "frontend.enableUpdateWorkflowExecution=true"
```

In a second terminal:
2. Create search attributes in default namespace
```shell
temporal operator search-attribute create --name foo --type Text
temporal operator search-attribute create --name created_at --type Datetime
```
3. Create `external` namespace
```shell
temporal operator namespace create external
temporal operator search-attribute create --namespace external --name foo --type Text
temporal operator search-attribute create --namespace external --name created_at --type Datetime
```
3. Run `example` worker
```shell
go run example/main.go worker
```

In a third terminal:
1. Run `external` worker
```shell
go run example/main.go external worker
```

In a fourth terminal:
1. Execute a workflow
```shell
go run example/main.go external provision-foo --request-name test
```
2 changes: 0 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,3 @@ func main() {
log.Fatal(err)
}
}

// ============================================================================
32 changes: 27 additions & 5 deletions example/proto/example/v1/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ service Example {
execution_timeout: { seconds: 3600 }
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
id: 'create-foo/${! name.slug() }'
// search_attributes:
// 'foo = name\n'
// 'created_at = now().ts_tz("UTC")\n'
xns: {
heartbeat_interval: { seconds: 10 }
heartbeat_timeout: { seconds: 20 }
start_to_close_timeout: { seconds: 3630 }
}
search_attributes:
'foo = name\n'
'created_at = now().ts_tz("UTC")\n'
query: { ref: 'GetFooProgress' }
signal: { ref: 'SetFooProgress', start: true }
update: { ref: 'UpdateFooProgress' }
Expand All @@ -28,7 +33,13 @@ service Example {

// GetFooProgress returns the status of a CreateFoo operation
rpc GetFooProgress(google.protobuf.Empty) returns (GetFooProgressResponse) {
option (temporal.v1.query) = {};
option (temporal.v1.query) = {
xns: {
heartbeat_interval: { seconds: 10 }
heartbeat_timeout: { seconds: 20 }
start_to_close_timeout: { seconds: 60 }
}
};
}

// Notify sends a notification
Expand All @@ -43,13 +54,24 @@ service Example {

// SetFooProgress sets the current status of a CreateFoo operation
rpc SetFooProgress(SetFooProgressRequest) returns (google.protobuf.Empty) {
option (temporal.v1.signal) = {};
option (temporal.v1.signal) = {
xns: {
heartbeat_interval: { seconds: 10 }
heartbeat_timeout: { seconds: 20 }
start_to_close_timeout: { seconds: 60 }
}
};
}

// UpdateFooProgress sets the current status of a CreateFoo operation
rpc UpdateFooProgress(SetFooProgressRequest) returns (GetFooProgressResponse) {
option (temporal.v1.update) = {
id: 'update-progress/${! progress.string() }',
xns: {
heartbeat_interval: { seconds: 10 }
heartbeat_timeout: { seconds: 20 }
start_to_close_timeout: { seconds: 60 }
}
};
}
}
Expand Down
Loading

0 comments on commit 4987b47

Please sign in to comment.