-
Notifications
You must be signed in to change notification settings - Fork 107
initial work to support SignalExternalWorkflow #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
antstorm
merged 18 commits into
coinbase:master
from
chuckremes2:signal_external_workflow
Feb 14, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fb5e2dc
initial work to support SignalExternalWorkflow
chuckremes2 45fc693
define the serializer and hook it up
chuckremes2 df7f9be
stub in what I think is the correct work for each event type
chuckremes2 3b85c5c
some fixes per antstorm advice
chuckremes2 3ec41f7
initial attempt at integration test
chuckremes2 2b7cf11
docs on testing and an improvement to existing test
chuckremes2 4e7e8a3
encode the signal payload using correct helper
chuckremes2 9971c20
return a Future and fulfill it correctly upon completion
chuckremes2 82240ac
get the \*event_id from the right field in the command structure
chuckremes2 c274b68
modify test to verify the signal is only received once
chuckremes2 f65ce32
test for failure to deliver a signal to external workflow
chuckremes2 6f16c73
do not discard the failure command otherwise non-deterministic
chuckremes2 fe3aa4d
simplify test workflow by eliminating unnecessary timer
chuckremes2 820dfcc
oops, had double call to #schedule_command so signals were sent twice
chuckremes2 fd85b4b
edit description of example
chuckremes2 f53b947
split to separate files and improve test coverage
chuckremes2 e43066e
change method signature for consistency and a few other cleanups
chuckremes2 b888fe3
oops, fix EventType name to match correct constant
chuckremes2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
examples/spec/integration/wait_for_external_signal_workflow_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| require 'workflows/wait_for_external_signal_workflow' | ||
| require 'workflows/send_signal_to_external_workflow' | ||
|
|
||
| describe WaitForExternalSignalWorkflow do | ||
| let(:signal_name) { "signal_name" } | ||
| let(:receiver_workflow_id) { SecureRandom.uuid } | ||
| let(:sender_workflow_id) { SecureRandom.uuid } | ||
|
|
||
| context 'when the workflows succeed then' do | ||
| it 'receives signal from an external workflow only once' do | ||
| run_id = Temporal.start_workflow( | ||
| WaitForExternalSignalWorkflow, | ||
| signal_name, | ||
| options: {workflow_id: receiver_workflow_id} | ||
| ) | ||
|
|
||
| Temporal.start_workflow( | ||
| SendSignalToExternalWorkflow, | ||
| signal_name, | ||
| receiver_workflow_id | ||
| ) | ||
|
|
||
| result = Temporal.await_workflow_result( | ||
| WaitForExternalSignalWorkflow, | ||
| workflow_id: receiver_workflow_id, | ||
| run_id: run_id, | ||
| ) | ||
|
|
||
| expect(result).to eq( | ||
| { | ||
| received: { | ||
| signal_name => ["arg1", "arg2"] | ||
| }, | ||
| counts: { | ||
| signal_name => 1 | ||
| } | ||
| } | ||
| ) | ||
| end | ||
|
|
||
| it 'returns :success to the sending workflow' do | ||
| Temporal.start_workflow( | ||
| WaitForExternalSignalWorkflow, | ||
| signal_name, | ||
| options: {workflow_id: receiver_workflow_id} | ||
| ) | ||
|
|
||
| run_id = Temporal.start_workflow( | ||
| SendSignalToExternalWorkflow, | ||
| signal_name, | ||
| receiver_workflow_id, | ||
| options: {workflow_id: sender_workflow_id} | ||
| ) | ||
|
|
||
| result = Temporal.await_workflow_result( | ||
| SendSignalToExternalWorkflow, | ||
| workflow_id: sender_workflow_id, | ||
| run_id: run_id, | ||
| ) | ||
|
|
||
| expect(result).to eq(:success) | ||
| end | ||
| end | ||
|
|
||
| context 'when the workflows fail' do | ||
| it 'correctly handles failure to deliver' do | ||
| run_id = Temporal.start_workflow( | ||
| SendSignalToExternalWorkflow, | ||
| signal_name, | ||
| receiver_workflow_id, | ||
| options: {workflow_id: sender_workflow_id}) | ||
|
|
||
| result = Temporal.await_workflow_result( | ||
| SendSignalToExternalWorkflow, | ||
| workflow_id: sender_workflow_id, | ||
| run_id: run_id, | ||
| ) | ||
|
|
||
| expect(result).to eq(:failed) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Sends +signal_name+ to the +target_workflow+ from within a workflow. | ||
| # This is different than using the Client#send_signal method which is | ||
| # for signaling a workflow *from outside* any workflow. | ||
| # | ||
| # Returns :success or :failed | ||
| # | ||
| class SendSignalToExternalWorkflow < Temporal::Workflow | ||
| def execute(signal_name, target_workflow) | ||
| logger.info("Send a signal to an external workflow") | ||
| future = workflow.signal_external_workflow(WaitForExternalSignalWorkflow, signal_name, target_workflow, nil, ["arg1", "arg2"]) | ||
| @status = nil | ||
| future.done { @status = :success } | ||
| future.failed { @status = :failed } | ||
| future.get | ||
| @status | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # One workflow sends a signal to another workflow. Can be used to implement | ||
| # the synchronous-proxy pattern (see Go samples) | ||
| # | ||
| class WaitForExternalSignalWorkflow < Temporal::Workflow | ||
| def execute(expected_signal) | ||
| signals_received = {} | ||
| signal_counts = Hash.new { |h,k| h[k] = 0 } | ||
|
|
||
| workflow.on_signal do |signal, input| | ||
| workflow.logger.info("Received signal name #{signal}, with input #{input.inspect}") | ||
| signals_received[signal] = input | ||
| signal_counts[signal] += 1 | ||
| end | ||
|
|
||
| workflow.wait_for do | ||
| workflow.logger.info("Awaiting #{expected_signal}, signals received so far: #{signals_received}") | ||
| signals_received.key?(expected_signal) | ||
| end | ||
|
|
||
| { received: signals_received, counts: signal_counts } | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lib/temporal/connection/serializer/signal_external_workflow.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| require 'temporal/connection/serializer/base' | ||
| require 'temporal/concerns/payloads' | ||
|
|
||
| module Temporal | ||
| module Connection | ||
| module Serializer | ||
| class SignalExternalWorkflow < Base | ||
| include Concerns::Payloads | ||
|
|
||
| def to_proto | ||
| Temporal::Api::Command::V1::Command.new( | ||
| command_type: Temporal::Api::Enums::V1::CommandType::COMMAND_TYPE_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION, | ||
| signal_external_workflow_execution_command_attributes: | ||
| Temporal::Api::Command::V1::SignalExternalWorkflowExecutionCommandAttributes.new( | ||
| namespace: object.namespace, | ||
| execution: serialize_execution(object.execution), | ||
| signal_name: object.signal_name, | ||
| input: to_signal_payloads(object.input), | ||
| control: "", # deprecated | ||
| child_workflow_only: object.child_workflow_only | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def serialize_execution(execution) | ||
| Temporal::Api::Common::V1::WorkflowExecution.new(workflow_id: execution[:workflow_id], run_id: execution[:run_id]) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.