diff --git a/.gitignore b/.gitignore index 6bdea961..33bb9632 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ test.log vendor/ # Executables produced by cadence-samples repo bin/ +docker-compose.yml diff --git a/README.md b/README.md index 1b35e36e..3c5c1ade 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/cmd/samples/README.md b/cmd/samples/README.md deleted file mode 100644 index 68678400..00000000 --- a/cmd/samples/README.md +++ /dev/null @@ -1,160 +0,0 @@ -# Cadence Samples -These are some samples to demonstrate 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 - -## Prerequisite -Run Cadence Server - -See instructions for running the Cadence Server: https://github.com/uber/cadence/blob/master/README.md - -## Steps to run samples -### Build Samples -* Build all the workflows at once -``` -make -``` -* Build a workflow individually -``` -make - -Example: - make helloworld -``` - -### Run HelloWorld Sample -* Start workers for helloworld workflow and activities -``` -./bin/helloworld -m worker -``` -* Start workflow execution for helloworld workflow -``` -./bin/helloworld -m trigger -``` -* Start workflow shadower for helloworld workflow -``` -./bin/helloworld -m shadower -``` - -### Commands to run other samples - -#### cron -``` -./bin/cron -m worker -``` -Start workflow every minute using cron. -``` -./bin/cron -m trigger -cron "* * * * *" -``` - -#### dsl -``` -./bin/dsl -m worker -``` -``` -./bin/dsl -m trigger -dslConfig cmd/samples/dsl/workflow1.yaml -./bin/dsl -m trigger -dslConfig cmd/samples/dsl/workflow2.yaml -``` - -#### expense -See more details in https://github.com/uber-common/cadence-samples/blob/master/cmd/samples/expense/README.md - -#### fileprocessing -``` -./bin/fileprocessing -m worker -``` -``` -./bin/fileprocessing -m trigger -``` - -#### recipes/branch -``` -./bin/branch -m worker -``` -Run branch workflow -``` -./bin/branch -m trigger -c branch -``` -Run parallel branch workflow -``` -./bin/branch -m trigger -c parallel this will run the parallel branch workflow -``` - -#### recipes/choice -``` -./bin/choice -m worker -``` -Run the single choice workflow -``` -./bin/choice -m trigger -c single -``` -Run the multi choice workflow -``` -./bin/choice -m trigger -c multi -``` - -#### greetings -``` -./bin/greetings -m worker -``` -``` -./bin/greetings -m trigger -``` - -#### pickfirst -``` -./bin/pickfirst -m worker -``` -``` -./bin/pickfirst -m trigger -``` - -#### retryactivity -``` -./bin/retryactivity -m worker -``` -``` -./bin/retryactivity -m trigger -``` - -#### splitmerge -``` -./bin/splitmerge -m worker -``` -``` -./bin/splitmerge -m trigger -``` - -#### timer -``` -./bin/timer -m worker -``` -``` -./bin/timer -m trigger -``` - -#### childworkflow -``` -./bin/childworkflow -m worker -``` -``` -./bin/childworkflow -m trigger -``` - -#### dynamic -``` -./bin/dynamic -m worker -``` -``` -./bin/dynamic -m trigger -``` - -#### search attributes -Before running this, Cadence Server need to run with advanced visibility store. -See https://github.com/uber/cadence/blob/master/docs/visibility-on-elasticsearch.md -``` -./bin/searchattributes -m worker -``` -``` -./bin/searchattributes -m trigger -``` \ No newline at end of file diff --git a/cmd/samples/expense/README.md b/cmd/samples/expense/README.md index 4169201a..4b79e1f1 100644 --- a/cmd/samples/expense/README.md +++ b/cmd/samples/expense/README.md @@ -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 ``` diff --git a/cmd/samples/pageflow/README.md b/cmd/samples/pageflow/README.md index 10ab373a..227bd6e9 100644 --- a/cmd/samples/pageflow/README.md +++ b/cmd/samples/pageflow/README.md @@ -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. diff --git a/cmd/samples/pageflow/src/server/config.js b/cmd/samples/pageflow/src/server/config.js index 7183f714..8be7cb3e 100644 --- a/cmd/samples/pageflow/src/server/config.js +++ b/cmd/samples/pageflow/src/server/config.js @@ -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, diff --git a/cmd/samples/recipes/cancelactivity/workflow.go b/cmd/samples/recipes/cancelactivity/workflow.go index d0479150..09cfb8c1 100644 --- a/cmd/samples/recipes/cancelactivity/workflow.go +++ b/cmd/samples/recipes/cancelactivity/workflow.go @@ -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 or CLI: 'cadence --do samples-domain wf cancel -w ' to cancel") + logger.Info("activity started, to cancel workflow, use ./cancelactivity -m cancel -w or CLI: 'cadence --do default wf cancel -w ' to cancel") for { select { case <-time.After(1 * time.Second): diff --git a/cmd/samples/recipes/greetings/replay_test.go b/cmd/samples/recipes/greetings/replay_test.go index ef9e7c86..7040caec 100644 --- a/cmd/samples/recipes/greetings/replay_test.go +++ b/cmd/samples/recipes/greetings/replay_test.go @@ -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) { diff --git a/cmd/samples/recipes/helloworld/replay_test.go b/cmd/samples/recipes/helloworld/replay_test.go index 63a82b9f..c5c0beb7 100644 --- a/cmd/samples/recipes/helloworld/replay_test.go +++ b/cmd/samples/recipes/helloworld/replay_test.go @@ -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() diff --git a/cmd/samples/recipes/searchattributes/searchattributes_workflow.go b/cmd/samples/recipes/searchattributes/searchattributes_workflow.go index 58e37483..9ea8b35d 100644 --- a/cmd/samples/recipes/searchattributes/searchattributes_workflow.go +++ b/cmd/samples/recipes/searchattributes/searchattributes_workflow.go @@ -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 ) diff --git a/cmd/samples/recovery/recovery_workflow.go b/cmd/samples/recovery/recovery_workflow.go index 03181fe3..189b921b 100644 --- a/cmd/samples/recovery/recovery_workflow.go +++ b/cmd/samples/recovery/recovery_workflow.go @@ -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 diff --git a/config/development.yaml b/config/development.yaml index 8bcb9279..2a7cd2c0 100644 --- a/config/development.yaml +++ b/config/development.yaml @@ -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" diff --git a/new_samples/client_samples/helloworld/hello_world_sample.go b/new_samples/client_samples/helloworld/hello_world_sample.go index 846d4274..c5534d40 100644 --- a/new_samples/client_samples/helloworld/hello_world_sample.go +++ b/new_samples/client_samples/helloworld/hello_world_sample.go @@ -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) diff --git a/new_samples/worker/worker.go b/new_samples/worker/worker.go index 500e1bc6..20f494c4 100644 --- a/new_samples/worker/worker.go +++ b/new_samples/worker/worker.go @@ -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" diff --git a/new_samples/workflows/cancel_workflow.go b/new_samples/workflows/cancel_workflow.go index e3402768..8dc9e646 100644 --- a/new_samples/workflows/cancel_workflow.go +++ b/new_samples/workflows/cancel_workflow.go @@ -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 ' to cancel") + logger.Info("activity started, to cancel workflow, use CLI: 'cadence --do default wf cancel -w ' to cancel") for { select { case <-time.After(1 * time.Second):