uber / cadence-java-samples

Other
96 stars 60 forks source link

Add signal samples #69

Closed chopincode closed 11 months ago

chopincode commented 11 months ago

Add a new simple Cadence sample for Signal workflow.

To run the signal workflow, try the following CLI. cadence --env development --domain samples-domain workflow start --tl cadence-samples-worker --et 6000 --workflow_type SignalWorkflow::getGreeting --input '{"message":"uber"}' This CLI should give you a workflow ID in return in the terminal.

Then use this workflow ID and pass a payload to the signal via cadence --env development --domain samples-domain workflow signal --workflow_id 47b2b165-2f7d-4cbd-bc3a-910f2d748d87 --name SignalWorkflow::waitForGreeting --input '"Hello"

You should see a log printed out in the terminal. You may change the input payload to see different greeting message.

The workflow will keep alive until you invoke the cancel signal. cadence --env development --domain samples-domain workflow signal --workflow_id <YOUR WORKFLOW ID> --name SignalWorkflow::cancel --input '' The workflow should be in Completed status after cancellation.

Also, split interface definition and implementation into two separate package as it is the Spring Boot tradition to do so.

shijiesheng commented 11 months ago

Running locally, it returns greeting with null message twice immediately after I started one signalworkflow. This seems wrong.

15:05:57.765 [workflow-root] INFO  c.u.c.s.s.w.impl.SignalWorkflowImpl - executing SignalWorkflow::getGreeting
15:05:57.766 [workflow-root] INFO  c.u.c.s.s.w.impl.SignalWorkflowImpl - greeting: null
15:05:57.766 [workflow-root] INFO  c.u.c.s.s.w.impl.SignalWorkflowImpl - greeting: null
15:07:02.108 ["SignalWorkflow::waitForGreeting" signal handler] INFO  c.u.c.s.s.w.impl.SignalWorkflowImpl - received signal from SignalWorkflow:waitForName
15:07:02.109 [workflow-root] INFO  c.u.c.s.s.w.impl.SignalWorkflowImpl - greeting: Hello, uber!
15:07:02.109 [workflow-root] INFO  c.u.c.s.s.w.impl.SignalWorkflowImpl - greeting: Hello, uber!