Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ test.log
vendor/
# Executables produced by cadence-samples repo
bin/
docker-compose.yml
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Cadence Samples ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/uber-common/cadence-samples/build.yml)

These are some samples to demostrate various capabilities of Cadence client and server. You can learn more about cadence at:
* Cadence: https://github.com/uber/cadence
* Cadence Client: https://github.com/uber-go/cadence-client
* Cadence Server: https://github.com/cadence-workflow/cadence
* Cadence Client: https://github.com/cadence-workflow/cadence-go-client

## Prerequisite
Run Cadence Server
## Prerequisite for running samples

See instructions for running the Cadence Server: https://github.com/uber/cadence/blob/master/README.md

See instructions for using CLI to register a domain(name as "samples-domain"): https://cadenceworkflow.io/docs/cli/#quick-start
or https://github.com/uber/cadence/blob/master/tools/cli/README.md
Run Cadence server:
```
curl -LO https://raw.githubusercontent.com/cadence-workflow/cadence/refs/heads/master/docker/docker-compose.yml
docker-compose up
```


## Steps to run samples
Expand All @@ -20,10 +20,12 @@ make
```

### Run HelloWorld Sample

* Start workers for helloworld workflow and activities
```
./bin/helloworld -m worker
```

* Start workflow execution for helloworld workflow
```
./bin/helloworld -m trigger
Expand Down
160 changes: 0 additions & 160 deletions cmd/samples/README.md

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/samples/expense/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ This sample workflow process an expense request. The key part of this sample is

# Sample Description
* Create a new expense report.
* Wait for the expense report to be approved. This could take an arbitrary amount of time. So the activity's Execute method has to return before it is actually approved. This is done by returning a special error so the framework knows the activity is not completed yet.
* When the expense is approved (or rejected), somewhere in the world needs to be notified, and it will need to call WorkflowClient.CompleteActivity() to tell cadence service that that activity is now completed. In this sample case, the dummy server do this job. In real world, you will need to register some listener to the expense system or you will need to have your own pulling agent to check for the expense status periodic.
* Wait for the expense report to be approved. This could take an arbitrary amount of time. So the activity's Execute method has to return before it is actually approved. This is done by returning a special error so the framework knows the activity is not completed yet.
* When the expense is approved (or rejected), somewhere in the world needs to be notified, and it will need to call WorkflowClient.CompleteActivity() to tell cadence service that that activity is now completed. In this sample case, the dummy server do this job. In real world, you will need to register some listener to the expense system or you will need to have your own pulling agent to check for the expense status periodic.
* After the wait activity is completed, it did the payment for the expense. (dummy step in this sample case)

This sample rely on an a dummy expense server to work.

# Steps To Run Sample
* You need a cadence service running. See https://github.com/uber/cadence/blob/master/README.md for more details.
* Start the dummy server
* You need a cadence service running. See https://github.com/cadence-workflow/cadence/blob/master/README.md for more details.
* Start the dummy server
```
./bin/expense_dummy
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/samples/pageflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ User interactions are implemented through workflow signals, and the latest workf
You should be able to inspect workflow run through Cadence UI (http://localhost:8088/ if you use the standard Cadence docker image).

# Steps to run locally
Make sure you start cadence server first and create the "samples-domain" domain.
Make sure you start cadence server first.

### `npm install`
Make sure you are running at least node v14 (`nvm use 14`) and install dependencies. May take a while for the first time installing these packages.
Expand Down
2 changes: 1 addition & 1 deletion cmd/samples/pageflow/src/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config = {
port: '4000',
},
cadence: {
domain: 'samples-domain',
domain: 'default',
executionStartToCloseTimeoutSeconds: 10 * 60, // workflow open for 10 minutes
retryDelay: 100,
retryMax: 5,
Expand Down
2 changes: 1 addition & 1 deletion cmd/samples/recipes/cancelactivity/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func sampleCancelWorkflow(ctx workflow.Context) (retError error) {

func activityToBeCanceled(ctx context.Context) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("activity started, to cancel workflow, use ./cancelactivity -m cancel -w <WorkflowID> or CLI: 'cadence --do samples-domain wf cancel -w <WorkflowID>' to cancel")
logger.Info("activity started, to cancel workflow, use ./cancelactivity -m cancel -w <WorkflowID> or CLI: 'cadence --do default wf cancel -w <WorkflowID>' to cancel")
for {
select {
case <-time.After(1 * time.Second):
Expand Down
2 changes: 1 addition & 1 deletion cmd/samples/recipes/greetings/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// This replay test is the recommended way to make sure changing workflow code is backward compatible without non-deterministic errors.
// "greetings.json" can be downloaded from cadence CLI:
//
// cadence --do samples-domain wf show -w greetings_5d5f8e5c-4807-444d-9dc5-80abea22a324 --output_filename ~/tmp/greetings.json
// cadence --do default wf show -w greetings_5d5f8e5c-4807-444d-9dc5-80abea22a324 --output_filename ~/tmp/greetings.json
//
// Or from Cadence Web UI. And you may need to change workflowType in the first event.
func TestReplayWorkflowHistoryFromFile(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/samples/recipes/helloworld/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

// This replay test is the recommended way to make sure changing workflow code is backward compatible without non-deterministic errors.
// "helloworld.json" can be downloaded from cadence CLI:
// cadence --do samples-domain wf show -w helloworld_d002cd3a-aeee-4a11-aa30-1c62385b4d87 --output_filename ~/tmp/helloworld.json
//
// cadence --do default wf show -w helloworld_d002cd3a-aeee-4a11-aa30-1c62385b4d87 --output_filename ~/tmp/helloworld.json
//
// Or from Cadence Web UI. And you may need to change workflowType in the first event.
func TestReplayWorkflowHistoryFromFile(t *testing.T) {
replayer := worker.NewWorkflowReplayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ClientKey int

const (
// DomainName used for this sample
DomainName = "samples-domain"
DomainName = "default"
// CadenceClientKey for retrieving cadence client from context
CadenceClientKey ClientKey = iota
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/samples/recovery/recovery_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ClientKey int

const (
// DomainName used for this sample
DomainName = "samples-domain"
DomainName = "default"

// CadenceClientKey for retrieving cadence client from context
CadenceClientKey ClientKey = iota
Expand Down
4 changes: 2 additions & 2 deletions config/development.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# config for sample
domain: "samples-domain"
domain: "default"
service: "cadence-frontend"
host: "127.0.0.1:7833"
host: "localhost:7833"
# config for emitting metrics
#prometheus:
# listenAddress: "127.0.0.1:9098"
4 changes: 2 additions & 2 deletions new_samples/client_samples/helloworld/hello_world_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func main() {
cadenceClient := worker.BuildCadenceClient()
logger := worker.BuildLogger()

domain := "cadence-samples"
tasklist := "cadence-samples-worker"
domain := "default"
tasklist := "default-tasklist"
workflowID := uuid.New().String()
requestID := uuid.New().String()
executionTimeout := int32(60)
Expand Down
2 changes: 1 addition & 1 deletion new_samples/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const (
HostPort = "127.0.0.1:7833"
Domain = "cadence-samples"
Domain = "default"
// TaskListName identifies set of client workflows, activities, and workers.
// It could be your group or client or application name.
TaskListName = "cadence-samples-worker"
Expand Down
2 changes: 1 addition & 1 deletion new_samples/workflows/cancel_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func CancelWorkflow(ctx workflow.Context) (retError error) {

func ActivityToBeCanceled(ctx context.Context) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("activity started, to cancel workflow, use CLI: 'cadence --do samples-domain wf cancel -w <WorkflowID>' to cancel")
logger.Info("activity started, to cancel workflow, use CLI: 'cadence --do default wf cancel -w <WorkflowID>' to cancel")
for {
select {
case <-time.After(1 * time.Second):
Expand Down