Skip to content

Commit c796a19

Browse files
authored
Merge branch 'master' into mTLS
2 parents 117a8bb + 232bcd8 commit c796a19

File tree

9 files changed

+441
-3
lines changed

9 files changed

+441
-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+

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export PATH := $(GOPATH)/bin:$(PATH)
77
default: test
88

99
PROGS = helloworld \
10+
blocks \
1011
versioning \
1112
delaystart \
1213
branch \
@@ -53,6 +54,7 @@ TEST_DIRS=./cmd/samples/cron \
5354
./cmd/samples/dsl \
5455
./cmd/samples/expense \
5556
./cmd/samples/fileprocessing \
57+
./cmd/samples/blocks \
5658
./cmd/samples/recipes/branch \
5759
./cmd/samples/recipes/choice \
5860
./cmd/samples/recipes/greetings \
@@ -83,6 +85,9 @@ cancelactivity:
8385
helloworld:
8486
go build -o bin/helloworld cmd/samples/recipes/helloworld/*.go
8587

88+
blocks:
89+
go build -o bin/blocks cmd/samples/blocks/*.go
90+
8691
delaystart:
8792
go build -o bin/delaystart cmd/samples/recipes/delaystart/*.go
8893

@@ -204,6 +209,7 @@ clean:
204209
rm -Rf $(BUILD)
205210

206211
bins: helloworld \
212+
blocks \
207213
versioning \
208214
delaystart \
209215
branch \

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

cmd/samples/blocks/blocks

32.4 MB
Binary file not shown.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package main
2+
3+
import (
4+
"time"
5+
6+
"go.uber.org/cadence/workflow"
7+
"go.uber.org/cadence/x/blocks"
8+
"go.uber.org/zap"
9+
)
10+
11+
/**
12+
* This is the blocks workflow sample that demonstrates JSON blob queries.
13+
*/
14+
15+
// ApplicationName is the task list for this sample
16+
const ApplicationName = "blocksGroup"
17+
18+
const blocksWorkflowName = "blocksWorkflow"
19+
20+
// This is an example of using the 'blocks' query response in a cadence query, in this example,
21+
// to select the lunch option.
22+
func blocksWorkflow(ctx workflow.Context, name string) error {
23+
ao := workflow.ActivityOptions{
24+
ScheduleToStartTimeout: time.Minute,
25+
StartToCloseTimeout: time.Minute,
26+
HeartbeatTimeout: time.Second * 20,
27+
}
28+
ctx = workflow.WithActivityOptions(ctx, ao)
29+
30+
logger := workflow.GetLogger(ctx)
31+
32+
votes := []map[string]string{}
33+
34+
workflow.SetQueryHandler(ctx, "options", func() (blocks.QueryResponse, error) {
35+
logger := workflow.GetLogger(ctx)
36+
logger.Info("Responding to 'options' query")
37+
38+
return makeResponse(votes), nil
39+
})
40+
41+
votesChan := workflow.GetSignalChannel(ctx, "lunch_order")
42+
workflow.Go(ctx, func(ctx workflow.Context) {
43+
for {
44+
var vote map[string]string
45+
votesChan.Receive(ctx, &vote)
46+
votes = append(votes, vote)
47+
}
48+
})
49+
defer func() {
50+
votesChan.Close()
51+
}()
52+
53+
err := workflow.Sleep(ctx, 30*time.Minute)
54+
if err != nil {
55+
logger.Error("Sleep failed", zap.Error(err))
56+
return err
57+
}
58+
59+
logger.Info("Workflow completed.", zap.Any("Result", votes))
60+
return nil
61+
}
62+
63+
// makeResponse creates the lunch query response payload based on the current votes
64+
func makeResponse(votes []map[string]string) blocks.QueryResponse {
65+
return blocks.New(
66+
blocks.NewMarkdownSection("## Lunch options\nWe're voting on where to order lunch today. Select the option you want to vote for."),
67+
blocks.NewDivider(),
68+
blocks.NewMarkdownSection(makeVoteTable(votes)),
69+
blocks.NewMarkdownSection(makeMenu()),
70+
blocks.NewSignalActions(
71+
blocks.NewSignalButton("Farmhouse", "lunch_order", map[string]string{"location": "farmhouse - red thai curry", "requests": "spicy"}),
72+
blocks.NewSignalButtonWithExternalWorkflow("Ethiopian", "no_lunch_order_walk_in_person", nil, "in-person-order-workflow", ""),
73+
blocks.NewSignalButton("Ler Ros", "lunch_order", map[string]string{"location": "Ler Ros", "meal": "tofo Bahn Mi"}),
74+
),
75+
)
76+
}
77+
78+
func makeMenu() string {
79+
80+
options := []struct {
81+
image string
82+
desc string
83+
}{
84+
{
85+
image: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Red_roast_duck_curry.jpg/200px-Red_roast_duck_curry.jpg",
86+
desc: "Farmhouse - Red Thai Curry: (Thai: แกง, romanized: kaeng, pronounced [kɛ̄ːŋ]) is a dish in Thai cuisine made from curry paste, coconut milk or water, meat, seafood, vegetables or fruit, and herbs. Curries in Thailand mainly differ from the Indian subcontinent in their use of ingredients such as fresh rhizomes, herbs, and aromatic leaves rather than a mix of dried spices.",
87+
},
88+
{
89+
image: "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/B%C3%A1nh_m%C3%AC_th%E1%BB%8Bt_n%C6%B0%E1%BB%9Bng.png/200px-B%C3%A1nh_m%C3%AC_th%E1%BB%8Bt_n%C6%B0%E1%BB%9Bng.png",
90+
desc: "Ler Ros: Lemongrass Tofu Bahn Mi: In Vietnamese cuisine, bánh mì, bánh mỳ or banh mi is a sandwich consisting of a baguette filled with various ingredients, most commonly including a protein such as pâté, chicken, or pork, and vegetables such as lettuce, cilantro, and cucumber.",
91+
},
92+
{
93+
image: "https://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Ethiopian_wat.jpg/960px-Ethiopian_wat.jpg",
94+
desc: "Ethiopian Wat: Wat is a traditional Ethiopian dish made from a mixture of spices, vegetables, and legumes. It is typically served with injera, a sourdough flatbread that is used to scoop up the food.",
95+
},
96+
}
97+
98+
table := "| Picture | Description |\n|---|----|\n"
99+
for _, option := range options {
100+
table += "| ![food](" + option.image + ") | " + option.desc + " |\n"
101+
}
102+
103+
table += "\n\n\n(source wikipedia)"
104+
105+
return table
106+
}
107+
108+
func makeVoteTable(votes []map[string]string) string {
109+
if len(votes) == 0 {
110+
return "| lunch order vote | meal | requests |\n|-------|-------|-------|\n| No votes yet |\n"
111+
}
112+
table := "| lunch order vote | meal | requests |\n|-------|-------|-------|\n"
113+
for _, vote := range votes {
114+
115+
loc := vote["location"]
116+
meal := vote["meal"]
117+
requests := vote["requests"]
118+
119+
table += "| " + loc + " | " + meal + " | " + requests + " |\n"
120+
}
121+
122+
return table
123+
}

0 commit comments

Comments
 (0)