Skip to content

Commit 86916ce

Browse files
committed
docs: add root README.md for migrated new_samples
1 parent 8f106e2 commit 86916ce

File tree

10 files changed

+780
-0
lines changed

10 files changed

+780
-0
lines changed

new_samples/branch/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Branch Sample
5+
6+
## Prerequisites
7+
8+
0. Install Cadence CLI. See instruction [here](https://cadenceworkflow.io/docs/cli/).
9+
1. Run the Cadence server:
10+
1. Clone the [Cadence](https://github.com/cadence-workflow/cadence) repository if you haven't done already: `git clone https://github.com/cadence-workflow/cadence.git`
11+
2. Run `docker compose -f docker/docker-compose.yml up` to start Cadence server
12+
3. See more details at https://github.com/uber/cadence/blob/master/README.md
13+
2. Once everything is up and running in Docker, open [localhost:8088](localhost:8088) to view Cadence UI.
14+
3. Register the `cadence-samples` domain:
15+
16+
```bash
17+
cadence --env development --domain cadence-samples domain register
18+
```
19+
20+
Refresh the [domains page](http://localhost:8088/domains) from step 2 to verify `cadence-samples` is registered.
21+
22+
## Steps to run sample
23+
24+
Inside the folder this sample is defined, run the following command:
25+
26+
```bash
27+
go run .
28+
```
29+
30+
This will call the main function in main.go which starts the worker, which will be execute the sample workflow code
31+
32+
## Branch Workflow Sample
33+
34+
This sample demonstrates **parallel activity execution** using Futures.
35+
36+
### Start the Workflow
37+
38+
```bash
39+
cadence --env development \
40+
--domain cadence-samples \
41+
workflow start \
42+
--tl cadence-samples-worker \
43+
--et 60 \
44+
--workflow_type cadence_samples.BranchWorkflow
45+
```
46+
47+
### Key Concept: Parallel Execution with Futures
48+
49+
```go
50+
var futures []workflow.Future
51+
for i := 1; i <= 3; i++ {
52+
future := workflow.ExecuteActivity(ctx, BranchActivity, input)
53+
futures = append(futures, future)
54+
}
55+
// Wait for all
56+
for _, f := range futures {
57+
f.Get(ctx, nil)
58+
}
59+
```
60+
61+
62+
## References
63+
64+
* The website: https://cadenceworkflow.io
65+
* Cadence's server: https://github.com/uber/cadence
66+
* Cadence's Go client: https://github.com/uber-go/cadence-client
67+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Cancel Activity Sample
5+
6+
## Prerequisites
7+
8+
0. Install Cadence CLI. See instruction [here](https://cadenceworkflow.io/docs/cli/).
9+
1. Run the Cadence server:
10+
1. Clone the [Cadence](https://github.com/cadence-workflow/cadence) repository if you haven't done already: `git clone https://github.com/cadence-workflow/cadence.git`
11+
2. Run `docker compose -f docker/docker-compose.yml up` to start Cadence server
12+
3. See more details at https://github.com/uber/cadence/blob/master/README.md
13+
2. Once everything is up and running in Docker, open [localhost:8088](localhost:8088) to view Cadence UI.
14+
3. Register the `cadence-samples` domain:
15+
16+
```bash
17+
cadence --env development --domain cadence-samples domain register
18+
```
19+
20+
Refresh the [domains page](http://localhost:8088/domains) from step 2 to verify `cadence-samples` is registered.
21+
22+
## Steps to run sample
23+
24+
Inside the folder this sample is defined, run the following command:
25+
26+
```bash
27+
go run .
28+
```
29+
30+
This will call the main function in main.go which starts the worker, which will be execute the sample workflow code
31+
32+
## How It Works
33+
34+
This sample demonstrates graceful workflow cancellation with cleanup:
35+
36+
```
37+
┌──────────────────────┐
38+
│ CancelWorkflow │
39+
│ │
40+
│ ┌────────────────┐ │ Cancel Signal
41+
│ │ LongRunning │◀─┼─────────────────────
42+
│ │ Activity │ │
43+
│ │ (heartbeating) │ │
44+
│ └───────┬────────┘ │
45+
│ │ │
46+
│ On Cancel: │
47+
│ ▼ │
48+
│ ┌────────────────┐ │
49+
│ │ CleanupActivity│ │ ← Runs in disconnected context
50+
│ └────────────────┘ │
51+
└──────────────────────┘
52+
```
53+
54+
Key concepts:
55+
- **WaitForCancellation**: Activity option that waits for activity to acknowledge cancel
56+
- **NewDisconnectedContext**: Creates a context unaffected by workflow cancellation
57+
- **IsCanceledError**: Check if an error is due to cancellation
58+
59+
## Running the Sample
60+
61+
Start the worker:
62+
```bash
63+
go run .
64+
```
65+
66+
Trigger a workflow:
67+
```bash
68+
cadence --env development \
69+
--domain cadence-samples \
70+
workflow start \
71+
--workflow_type cadence_samples.CancelWorkflow \
72+
--tl cadence-samples-worker \
73+
--et 600
74+
```
75+
76+
Cancel the workflow (copy workflow ID from above):
77+
```bash
78+
cadence --env development \
79+
--domain cadence-samples \
80+
workflow cancel \
81+
--wid <workflow_id>
82+
```
83+
84+
Watch the worker logs to see the cleanup activity run.
85+
86+
## References
87+
88+
* The website: https://cadenceworkflow.io
89+
* Cadence's server: https://github.com/uber/cadence
90+
* Cadence's Go client: https://github.com/uber-go/cadence-client
91+

new_samples/choice/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Choice Sample
5+
6+
## Prerequisites
7+
8+
0. Install Cadence CLI. See instruction [here](https://cadenceworkflow.io/docs/cli/).
9+
1. Run the Cadence server:
10+
1. Clone the [Cadence](https://github.com/cadence-workflow/cadence) repository if you haven't done already: `git clone https://github.com/cadence-workflow/cadence.git`
11+
2. Run `docker compose -f docker/docker-compose.yml up` to start Cadence server
12+
3. See more details at https://github.com/uber/cadence/blob/master/README.md
13+
2. Once everything is up and running in Docker, open [localhost:8088](localhost:8088) to view Cadence UI.
14+
3. Register the `cadence-samples` domain:
15+
16+
```bash
17+
cadence --env development --domain cadence-samples domain register
18+
```
19+
20+
Refresh the [domains page](http://localhost:8088/domains) from step 2 to verify `cadence-samples` is registered.
21+
22+
## Steps to run sample
23+
24+
Inside the folder this sample is defined, run the following command:
25+
26+
```bash
27+
go run .
28+
```
29+
30+
This will call the main function in main.go which starts the worker, which will be execute the sample workflow code
31+
32+
## Choice Workflow Sample
33+
34+
This sample demonstrates **conditional execution** based on activity results.
35+
36+
### Start the Workflow
37+
38+
```bash
39+
cadence --env development \
40+
--domain cadence-samples \
41+
workflow start \
42+
--tl cadence-samples-worker \
43+
--et 60 \
44+
--workflow_type cadence_samples.ChoiceWorkflow
45+
```
46+
47+
### Key Concept: Conditional Branching
48+
49+
```go
50+
var order string
51+
workflow.ExecuteActivity(ctx, GetOrderActivity).Get(ctx, &order)
52+
switch order {
53+
case "apple":
54+
workflow.ExecuteActivity(ctx, ProcessAppleActivity)
55+
case "banana":
56+
workflow.ExecuteActivity(ctx, ProcessBananaActivity)
57+
}
58+
```
59+
60+
61+
## References
62+
63+
* The website: https://cadenceworkflow.io
64+
* Cadence's server: https://github.com/uber/cadence
65+
* Cadence's Go client: https://github.com/uber-go/cadence-client
66+

new_samples/delaystart/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Delay Start Sample
5+
6+
## Prerequisites
7+
8+
0. Install Cadence CLI. See instruction [here](https://cadenceworkflow.io/docs/cli/).
9+
1. Run the Cadence server:
10+
1. Clone the [Cadence](https://github.com/cadence-workflow/cadence) repository if you haven't done already: `git clone https://github.com/cadence-workflow/cadence.git`
11+
2. Run `docker compose -f docker/docker-compose.yml up` to start Cadence server
12+
3. See more details at https://github.com/uber/cadence/blob/master/README.md
13+
2. Once everything is up and running in Docker, open [localhost:8088](localhost:8088) to view Cadence UI.
14+
3. Register the `cadence-samples` domain:
15+
16+
```bash
17+
cadence --env development --domain cadence-samples domain register
18+
```
19+
20+
Refresh the [domains page](http://localhost:8088/domains) from step 2 to verify `cadence-samples` is registered.
21+
22+
## Steps to run sample
23+
24+
Inside the folder this sample is defined, run the following command:
25+
26+
```bash
27+
go run .
28+
```
29+
30+
This will call the main function in main.go which starts the worker, which will be execute the sample workflow code
31+
32+
## How It Works
33+
34+
This sample demonstrates deferred workflow execution using `DelayStart` option:
35+
36+
```
37+
workflow start --delay_start 30s
38+
39+
40+
┌───────────────────┐
41+
│ Workflow waits │ ← Cadence delays start by 30s
42+
│ in pending state │
43+
└───────────────────┘
44+
45+
▼ (after delay)
46+
┌───────────────────┐
47+
│DelayStartWorkflow │
48+
│ │ │
49+
│ ▼ │
50+
│DelayStartActivity │
51+
└───────────────────┘
52+
```
53+
54+
The delay is handled by Cadence, not by the workflow code.
55+
56+
## Running the Sample
57+
58+
Start the worker:
59+
```bash
60+
go run .
61+
```
62+
63+
Start a workflow with 30-second delay:
64+
```bash
65+
cadence --env development \
66+
--domain cadence-samples \
67+
workflow start \
68+
--workflow_type cadence_samples.DelayStartWorkflow \
69+
--tl cadence-samples-worker \
70+
--et 600 \
71+
--delay_start 30s \
72+
--input '"30s"'
73+
```
74+
75+
The workflow will remain in "pending" state for 30 seconds before starting.
76+
77+
## References
78+
79+
* The website: https://cadenceworkflow.io
80+
* Cadence's server: https://github.com/uber/cadence
81+
* Cadence's Go client: https://github.com/uber-go/cadence-client
82+

new_samples/dynamic/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Dynamic Invocation Sample
5+
6+
## Prerequisites
7+
8+
0. Install Cadence CLI. See instruction [here](https://cadenceworkflow.io/docs/cli/).
9+
1. Run the Cadence server:
10+
1. Clone the [Cadence](https://github.com/cadence-workflow/cadence) repository if you haven't done already: `git clone https://github.com/cadence-workflow/cadence.git`
11+
2. Run `docker compose -f docker/docker-compose.yml up` to start Cadence server
12+
3. See more details at https://github.com/uber/cadence/blob/master/README.md
13+
2. Once everything is up and running in Docker, open [localhost:8088](localhost:8088) to view Cadence UI.
14+
3. Register the `cadence-samples` domain:
15+
16+
```bash
17+
cadence --env development --domain cadence-samples domain register
18+
```
19+
20+
Refresh the [domains page](http://localhost:8088/domains) from step 2 to verify `cadence-samples` is registered.
21+
22+
## Steps to run sample
23+
24+
Inside the folder this sample is defined, run the following command:
25+
26+
```bash
27+
go run .
28+
```
29+
30+
This will call the main function in main.go which starts the worker, which will be execute the sample workflow code
31+
32+
## How It Works
33+
34+
This sample demonstrates invoking activities by **string name** rather than function reference:
35+
36+
```go
37+
// Instead of:
38+
workflow.ExecuteActivity(ctx, GetGreetingActivity)
39+
40+
// Use string name:
41+
workflow.ExecuteActivity(ctx, "main.getGreetingActivity")
42+
```
43+
44+
This enables:
45+
- Plugin architectures where activities are loaded at runtime
46+
- Configuration-driven workflows
47+
- Cross-language activity invocation
48+
49+
```
50+
┌─────────────────────────┐
51+
│ DynamicGreetingsWorkflow│
52+
│ │
53+
│ ExecuteActivity(ctx, │
54+
│ "main.getGreeting") │──▶ GetGreetingActivity
55+
│ │ │
56+
│ ExecuteActivity(ctx, │
57+
│ "main.getName") │──▶ GetNameActivity
58+
│ │ │
59+
│ ExecuteActivity(ctx, │
60+
│ "main.sayGreeting") │──▶ SayGreetingActivity
61+
└─────────────────────────┘
62+
```
63+
64+
## Running the Sample
65+
66+
Start the worker:
67+
```bash
68+
go run .
69+
```
70+
71+
Trigger the workflow:
72+
```bash
73+
cadence --env development \
74+
--domain cadence-samples \
75+
workflow start \
76+
--workflow_type cadence_samples.DynamicGreetingsWorkflow \
77+
--tl cadence-samples-worker \
78+
--et 60
79+
```
80+
81+
82+
## References
83+
84+
* The website: https://cadenceworkflow.io
85+
* Cadence's server: https://github.com/uber/cadence
86+
* Cadence's Go client: https://github.com/uber-go/cadence-client
87+

0 commit comments

Comments
 (0)