Skip to content

Commit 5e88cc2

Browse files
Introduce the new structure
Signed-off-by: Ender Demirkaya <[email protected]>
1 parent aaacf61 commit 5e88cc2

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed
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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package main
2+
3+
import (
4+
"io"
5+
"os"
6+
"text/template"
7+
)
8+
9+
type TemplateData struct {
10+
SampleName string
11+
Workflows []string
12+
Activities []string
13+
}
14+
15+
func main() {
16+
// Define the data for HelloWorld
17+
data := TemplateData{
18+
SampleName: "Hello World",
19+
Workflows: []string{"HelloWorldWorkflow"},
20+
Activities: []string{"HelloWorldActivity"},
21+
}
22+
23+
// Generate worker.go
24+
generateFile("../../template/worker.tmpl", "../worker.go", data)
25+
println("Generated worker.go")
26+
27+
// Generate main.go
28+
generateFile("../../template/main.tmpl", "../main.go", data)
29+
println("Generated main.go")
30+
31+
// Generate README.md (combine template + specific + references)
32+
generateREADME("../../template/README.tmpl", "README_specific.md", "../../template/README_references.md", "../README.md", data)
33+
println("Generated README.md")
34+
}
35+
36+
func generateFile(templatePath, outputPath string, data TemplateData) {
37+
tmpl, err := template.ParseFiles(templatePath)
38+
if err != nil {
39+
panic("Failed to parse template " + templatePath + ": " + err.Error())
40+
}
41+
42+
f, err := os.Create(outputPath)
43+
if err != nil {
44+
panic("Failed to create output file " + outputPath + ": " + err.Error())
45+
}
46+
defer f.Close()
47+
48+
err = tmpl.Execute(f, data)
49+
if err != nil {
50+
panic("Failed to execute template: " + err.Error())
51+
}
52+
}
53+
54+
func generateREADME(templatePath, specificPath, referencesPath, outputPath string, data TemplateData) {
55+
// Create output file
56+
f, err := os.Create(outputPath)
57+
if err != nil {
58+
panic("Failed to create README file: " + err.Error())
59+
}
60+
defer f.Close()
61+
62+
// First, write the generic template part
63+
tmpl, err := template.ParseFiles(templatePath)
64+
if err != nil {
65+
panic("Failed to parse README template: " + err.Error())
66+
}
67+
68+
err = tmpl.Execute(f, data)
69+
if err != nil {
70+
panic("Failed to execute README template: " + err.Error())
71+
}
72+
73+
// Then, append the specific content
74+
specific, err := os.Open(specificPath)
75+
if err != nil {
76+
panic("Failed to open specific README content: " + err.Error())
77+
}
78+
defer specific.Close()
79+
80+
_, err = io.Copy(f, specific)
81+
if err != nil {
82+
panic("Failed to append specific README content: " + err.Error())
83+
}
84+
85+
// Finally, append the references
86+
references, err := os.Open(referencesPath)
87+
if err != nil {
88+
panic("Failed to open references content: " + err.Error())
89+
}
90+
defer references.Close()
91+
92+
_, err = io.Copy(f, references)
93+
if err != nil {
94+
panic("Failed to append references content: " + err.Error())
95+
}
96+
}
97+
98+

0 commit comments

Comments
 (0)