Skip to content

Commit e0e2ad8

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents c26d63f + c270d26 commit e0e2ad8

File tree

18 files changed

+694
-3
lines changed

18 files changed

+694
-3
lines changed

CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Contributing to Cadence Samples
2+
3+
This doc is intended for contributors to Cadence samples. Thanks for considering to contribute ❤️
4+
5+
> 📚 **New to contributing to Cadence?** Check out our [Contributing Guide](https://cadenceworkflow.io/community/how-to-contribute/getting-started) for an overview of the contribution process across all Cadence repositories. This document contains cadence-samples specific setup and development instructions.
6+
7+
Once you go through the rest of this doc and get familiar with local development setup, take a look at the list of issues labeled with
8+
[good first issue](https://github.com/uber-common/cadence-samples/labels/good%20first%20issue).
9+
10+
Join our community on the CNCF Slack workspace at [cloud-native.slack.com](https://communityinviter.com/apps/cloud-native/cncf) in the **#cadence-users** channel to reach out and discuss issues with the team.
11+
12+
### Documentation
13+
14+
- Every sample must have a README.md
15+
- Include:
16+
- What the sample demonstrates
17+
- Real-world use cases
18+
- How to run the sample
19+
- Expected output
20+
- Key concepts
21+
22+
### Getting Help
23+
24+
If you need help or have questions:
25+
26+
- Join [CNCF Slack #cadence-users](https://communityinviter.com/apps/cloud-native/cncf)
27+
- Ask on [StackOverflow](https://stackoverflow.com/questions/tagged/cadence-workflow) with tag `cadence-workflow`
28+
- Open a [GitHub Discussion](https://github.com/uber-common/cadence-samples/discussions)
29+
- File an [issue](https://github.com/uber-common/cadence-samples/issues) for bugs
30+
31+
## Code of Conduct
32+
33+
Please be respectful and constructive in all interactions. We're all here to learn and help each other build better software.
34+
35+
## License
36+
37+
By contributing, you agree that your contributions will be licensed under the Apache 2.0 License.
38+
39+
---
40+
41+
Thank you for contributing to Cadence samples! Your efforts help the entire community. 🚀
42+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Learn more about Cadence at:
1515
- [Documentation](https://cadenceworkflow.io)
1616
- [Cadence Server](https://github.com/cadence-workflow/cadence)
1717
- [Cadence Go Client](https://github.com/cadence-workflow/cadence-go-client)
18+
- [CNCF Slack](https://communityinviter.com/apps/cloud-native/cncf) - Join **#cadence-users** channel on CNCF Slack
1819

1920
## 🚀 Quick Start
2021

new_samples/client_samples/helloworld_tls/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ https://github.com/cadence-workflow/cadence/blob/e1267de12f8bc670fc84fab456d3495
1919
```
2020

2121
4. **Start cadence server with TLS**
22-
```bash
23-
./cadence-server --env development --zone tls start
24-
```
22+
To enable mTLS in Cadence server, you need to configure TLS settings and start the server with the appropriate environment configuration.
23+
Starting the Server with TLS
24+
Use the --zone flag to specify the TLS configuration when starting the Cadence server:
25+
26+
./cadence-server --env development --zone tls start
27+
28+
This will load [config/development.yaml](https://github.com/cadence-workflow/cadence/blob/e1267de12f8bc670fc84fab456d3495c8fc2f8a8/config/development.yaml) + [config/development_tls.yaml](https://github.com/cadence-workflow/cadence/blob/e1267de12f8bc670fc84fab456d3495c8fc2f8a8/config/development_tls.yaml).
29+
See [CONTRIBUTING.md](https://github.com/cadence-workflow/cadence/blob/e1267de12f8bc670fc84fab456d3495c8fc2f8a8/CONTRIBUTING.md#4-run) for more details.
2530

2631
## Running the Sample
2732

new_samples/client_samples/helloworld_tls/hello_world_tls.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ func withTLSDialOption() (grpc.DialOption, error) {
8080
RootCAs: caCertPool,
8181
Certificates: []tls.Certificate{clientCert},
8282
}
83+
// Create TLS credentials from the TLS configuration
8384
creds := credentials.NewTLS(&tlsConfig)
85+
// Create a gRPC dial option with TLS credentials for secure connection
8486
grpc.DialerCredentials(creds)
87+
// Return the gRPC dial option configured with TLS credentials
8588
return grpc.DialerCredentials(creds), nil
8689
}

new_samples/hello_world/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Hello World 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+
### Start your workflow
33+
34+
This workflow takes an input message and greet you as response. Try the following CLI
35+
36+
```bash
37+
cadence --env development \
38+
--domain cadence-samples \
39+
workflow start \
40+
--workflow_type cadence_samples.HelloWorldWorkflow \
41+
--tl cadence-samples-worker \
42+
--et 60 \
43+
--input '{"message":"Cadence"}'
44+
```
45+
46+
Here are the details to this command:
47+
48+
* `--domain` option describes under which domain to run this workflow
49+
* `--env development` calls the "local" cadence server
50+
* `--workflow_type` option describes which workflow to execute
51+
* `-tl` (or `--tasklist`) tells cadence-server which tasklist to schedule tasks with. This is the same tasklist the worker polls tasks from. See worker.go
52+
* `--et` (or `--execution_timeout`) tells cadence server how long to wait until timing out the workflow
53+
* `--input` is the input to your workflow
54+
55+
To see more options run `cadence --help`
56+
57+
### View your workflow
58+
59+
#### Cadence UI (cadence-web)
60+
61+
Click on `cadence-samples` domain in cadence-web to view your workflow.
62+
63+
* In Summary tab, you will see the input and output to your workflow
64+
* Click on History tab to see individual steps.
65+
66+
#### CLI
67+
68+
List workflows using the following command:
69+
70+
```bash
71+
cadence --env development --domain cadence-samples --workflow list
72+
```
73+
74+
You can view an individual workflow by using the following command:
75+
76+
```bash
77+
cadence --env development \
78+
--domain cadence-samples \
79+
--workflow describe \
80+
--wid <workflow_id>
81+
```
82+
83+
* `workflow` is the noun to run commands within workflow scope
84+
* `describe` is the verb to return the summary of the workflow
85+
* `--wid` (or `--workflow_id`) is the option to pass the workflow id. If there are multiple "run"s, it will return the latest one.
86+
* (optional) `--rid` (or `--run_id`) is the option to pass the run id to describe a specific run, instead of the latest.
87+
88+
To view the entire history of the workflow, use the following command:
89+
90+
```bash
91+
cadence --env development \
92+
--domain cadence-samples \
93+
--workflow show \
94+
--wid <workflow_id>
95+
```
96+
97+
## References
98+
99+
* The website: https://cadenceworkflow.io
100+
* Cadence's server: https://github.com/uber/cadence
101+
* Cadence's Go client: https://github.com/uber-go/cadence-client
102+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- THIS IS A GENERATED FILE -->
2+
<!-- PLEASE DO NOT EDIT -->
3+
4+
# Sample Generator
5+
6+
This folder is NOT part of the actual sample. It exists only for contributors who work on this sample. Please disregard it if you are trying to learn about Cadence.
7+
8+
To create a better learning experience for Cadence users, each sample folder is designed to be self contained. Users can view every part of writing and running workflows, including:
9+
10+
* Cadence client initialization
11+
* Worker with workflow and activity registrations
12+
* Workflow starter
13+
* and the workflow code itself
14+
15+
Some samples may have more or fewer parts depending on what they need to demonstrate.
16+
17+
In most cases, the workflow code (e.g. `workflow.go`) is the part that users care about. The rest is boilerplate needed to run that workflow. For each sample folder, the workflow code should be written by hand. The boilerplate can be generated. Keeping all parts inside one folder gives early learners more value because they can see everything together rather than jumping across directories.
18+
19+
## Contributing
20+
21+
* When creating a new sample, follow the steps mentioned in the README file in the main samples folder.
22+
* To update the sample workflow code, edit the workflow file directly.
23+
* To update the worker, client, or other boilerplate logic, edit the generator file. If your change applies to all samples, update the common generator file inside the `template` folder. Edit the generator file in this folder only when the change should affect this sample alone.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
### Start your workflow
2+
3+
This workflow takes an input message and greet you as response. Try the following CLI
4+
5+
```bash
6+
cadence --env development \
7+
--domain cadence-samples \
8+
workflow start \
9+
--workflow_type cadence_samples.HelloWorldWorkflow \
10+
--tl cadence-samples-worker \
11+
--et 60 \
12+
--input '{"message":"Cadence"}'
13+
```
14+
15+
Here are the details to this command:
16+
17+
* `--domain` option describes under which domain to run this workflow
18+
* `--env development` calls the "local" cadence server
19+
* `--workflow_type` option describes which workflow to execute
20+
* `-tl` (or `--tasklist`) tells cadence-server which tasklist to schedule tasks with. This is the same tasklist the worker polls tasks from. See worker.go
21+
* `--et` (or `--execution_timeout`) tells cadence server how long to wait until timing out the workflow
22+
* `--input` is the input to your workflow
23+
24+
To see more options run `cadence --help`
25+
26+
### View your workflow
27+
28+
#### Cadence UI (cadence-web)
29+
30+
Click on `cadence-samples` domain in cadence-web to view your workflow.
31+
32+
* In Summary tab, you will see the input and output to your workflow
33+
* Click on History tab to see individual steps.
34+
35+
#### CLI
36+
37+
List workflows using the following command:
38+
39+
```bash
40+
cadence --env development --domain cadence-samples --workflow list
41+
```
42+
43+
You can view an individual workflow by using the following command:
44+
45+
```bash
46+
cadence --env development \
47+
--domain cadence-samples \
48+
--workflow describe \
49+
--wid <workflow_id>
50+
```
51+
52+
* `workflow` is the noun to run commands within workflow scope
53+
* `describe` is the verb to return the summary of the workflow
54+
* `--wid` (or `--workflow_id`) is the option to pass the workflow id. If there are multiple "run"s, it will return the latest one.
55+
* (optional) `--rid` (or `--run_id`) is the option to pass the run id to describe a specific run, instead of the latest.
56+
57+
To view the entire history of the workflow, use the following command:
58+
59+
```bash
60+
cadence --env development \
61+
--domain cadence-samples \
62+
--workflow show \
63+
--wid <workflow_id>
64+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import "github.com/uber-common/cadence-samples/new_samples/template"
4+
5+
func main() {
6+
// Define the data for HelloWorld
7+
data := template.TemplateData{
8+
SampleName: "Hello World",
9+
Workflows: []string{"HelloWorldWorkflow"},
10+
Activities: []string{"HelloWorldActivity"},
11+
}
12+
13+
template.GenerateAll(data)
14+
}
15+
16+
// Implement custom generator below

new_samples/hello_world/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// THIS IS A GENERATED FILE
2+
// PLEASE DO NOT EDIT
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"os"
9+
"os/signal"
10+
"syscall"
11+
)
12+
13+
func main() {
14+
StartWorker()
15+
16+
done := make(chan os.Signal, 1)
17+
signal.Notify(done, syscall.SIGINT)
18+
fmt.Println("Cadence worker started, press ctrl+c to terminate...")
19+
<-done
20+
}

0 commit comments

Comments
 (0)