Skip to content

Commit 1c3cf35

Browse files
committed
docs: add root README.md for migrated new_samples
1 parent a8b480c commit 1c3cf35

File tree

5 files changed

+505
-0
lines changed

5 files changed

+505
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Child Workflow 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+
## Child Workflow Sample
33+
34+
This sample demonstrates **parent-child workflow relationships** and the **ContinueAsNew** pattern.
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.ParentWorkflow
45+
```
46+
47+
### What Happens
48+
49+
```
50+
┌─────────────────────┐
51+
│ ParentWorkflow │
52+
└──────────┬──────────┘
53+
54+
│ ExecuteChildWorkflow
55+
56+
┌─────────────────────┐
57+
│ ChildWorkflow │──┐
58+
│ (run 1 of 5) │ │
59+
└─────────────────────┘ │
60+
│ │ ContinueAsNew
61+
▼ │
62+
┌─────────────────────┐ │
63+
│ ChildWorkflow │──┤
64+
│ (run 2 of 5) │ │
65+
└─────────────────────┘ │
66+
│ │
67+
... ...
68+
│ │
69+
▼ │
70+
┌─────────────────────┐ │
71+
│ ChildWorkflow │◀─┘
72+
│ (run 5 of 5) │
73+
└─────────────────────┘
74+
75+
│ Returns result
76+
77+
┌─────────────────────┐
78+
│ ParentWorkflow │
79+
│ completes │
80+
└─────────────────────┘
81+
```
82+
83+
1. Parent workflow starts a child workflow
84+
2. Child workflow uses `ContinueAsNew` to restart itself 5 times
85+
3. After 5 runs, child completes and returns result to parent
86+
87+
### Key Concept: Child Workflow Options
88+
89+
```go
90+
cwo := workflow.ChildWorkflowOptions{
91+
WorkflowID: childID,
92+
ExecutionStartToCloseTimeout: time.Minute,
93+
}
94+
ctx = workflow.WithChildOptions(ctx, cwo)
95+
96+
err := workflow.ExecuteChildWorkflow(ctx, ChildWorkflow, args...).Get(ctx, &result)
97+
```
98+
99+
### Key Concept: ContinueAsNew
100+
101+
```go
102+
// Instead of recursion (which grows history), use ContinueAsNew
103+
return "", workflow.NewContinueAsNewError(ctx, ChildWorkflow, newArgs...)
104+
```
105+
106+
ContinueAsNew starts a new workflow run with fresh history, avoiding unbounded history growth.
107+
108+
109+
## References
110+
111+
* The website: https://cadenceworkflow.io
112+
* Cadence's server: https://github.com/uber/cadence
113+
* Cadence's Go client: https://github.com/uber-go/cadence-client
114+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Local 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+
## Local Activity Sample
33+
34+
This sample demonstrates **local activities** - lightweight activities that run in the workflow worker process.
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.LocalActivityWorkflow \
45+
--input '"test_0_1_data"'
46+
```
47+
48+
### What Happens
49+
50+
The workflow uses local activities to quickly check conditions, then runs regular activities only for matching conditions:
51+
52+
```
53+
Input: "test_0_1_data"
54+
55+
Local Activities (fast, no server round-trip):
56+
├── CheckCondition0("test_0_1_data") → true (contains "_0_")
57+
├── CheckCondition1("test_0_1_data") → true (contains "_1_")
58+
└── CheckCondition2("test_0_1_data") → false (no "_2_")
59+
60+
Regular Activities (only for matching conditions):
61+
├── ProcessActivity(0) → runs
62+
└── ProcessActivity(1) → runs
63+
```
64+
65+
### Key Concept: Local vs Regular Activity
66+
67+
```go
68+
// Local activity - runs in worker process, no server round-trip
69+
lao := workflow.LocalActivityOptions{
70+
ScheduleToCloseTimeout: time.Second,
71+
}
72+
ctx = workflow.WithLocalActivityOptions(ctx, lao)
73+
workflow.ExecuteLocalActivity(ctx, checkCondition, data)
74+
75+
// Regular activity - scheduled through server
76+
ao := workflow.ActivityOptions{
77+
ScheduleToStartTimeout: time.Minute,
78+
StartToCloseTimeout: time.Minute,
79+
}
80+
ctx = workflow.WithActivityOptions(ctx, ao)
81+
workflow.ExecuteActivity(ctx, processActivity, data)
82+
```
83+
84+
### When to Use Local Activities
85+
86+
**Good for:**
87+
- Fast validations/checks
88+
- Data transformations
89+
- Condition evaluation
90+
- Operations < 1 second
91+
92+
**Avoid for:**
93+
- Long-running operations
94+
- Operations needing retries
95+
- External API calls
96+
97+
98+
## References
99+
100+
* The website: https://cadenceworkflow.io
101+
* Cadence's server: https://github.com/uber/cadence
102+
* Cadence's Go client: https://github.com/uber-go/cadence-client
103+

new_samples/query/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Query 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+
## Query Workflow Sample
33+
34+
This sample demonstrates **workflow queries** - inspecting workflow state without affecting execution.
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 180 \
44+
--workflow_type cadence_samples.QueryWorkflow
45+
```
46+
47+
### Query the Workflow
48+
49+
While the workflow is running, query its state:
50+
51+
```bash
52+
cadence --env development \
53+
--domain cadence-samples \
54+
workflow query \
55+
--wid <workflow_id> \
56+
--qt state
57+
```
58+
59+
### What Happens
60+
61+
The workflow goes through states that you can query:
62+
63+
```
64+
Time 0: state = "started"
65+
Time 1s: state = "waiting on timer"
66+
Time 2m: state = "done" (workflow completes)
67+
```
68+
69+
### Key Concept: Query Handler
70+
71+
```go
72+
func QueryWorkflow(ctx workflow.Context) error {
73+
currentState := "started"
74+
75+
// Register query handler for "state" query type
76+
workflow.SetQueryHandler(ctx, "state", func() (string, error) {
77+
return currentState, nil
78+
})
79+
80+
currentState = "waiting on timer"
81+
workflow.NewTimer(ctx, 2*time.Minute).Get(ctx, nil)
82+
83+
currentState = "done"
84+
return nil
85+
}
86+
```
87+
88+
### Use Cases
89+
90+
- Progress monitoring dashboards
91+
- Debugging running workflows
92+
- Health checks without affecting execution
93+
94+
95+
## References
96+
97+
* The website: https://cadenceworkflow.io
98+
* Cadence's server: https://github.com/uber/cadence
99+
* Cadence's Go client: https://github.com/uber-go/cadence-client
100+

0 commit comments

Comments
 (0)