-
Notifications
You must be signed in to change notification settings - Fork 19
support for query functionality #75
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
Open
djung335
wants to merge
12
commits into
coinbase:master
Choose a base branch
from
djung335:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
24b1245
adding support for queries
ab16ce0
added relevant files for client query
6ad5e00
modified executor.rb, added tests for query_registry.rb
739f43f
implemented changes in thrift.rb, synced changes from task_processor.rb
a716bf6
synced over changes from serializer, minor changes elsewhere
231ec2a
implemented name change to_thrift among other minor changes
730f42a
added more tests
cd6ae7a
more testing progress
e4a17d9
initial changes to tests
7d7162c
most up to date tests
e60e9b5
suggested changes
178f2a7
removed puts statement
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env ruby | ||
| require_relative '../init' | ||
|
|
||
| Dir[File.expand_path('../workflows/*.rb', __dir__)].each { |f| require f } | ||
|
|
||
| workflow_class_name, workflow_id, run_id, query, args = ARGV | ||
| workflow_class = Object.const_get(workflow_class_name) | ||
|
|
||
| if ![workflow_class, workflow_id, run_id, query].all? | ||
| fail 'Wrong arguments, use `bin/query WORKFLOW WORKFLOW_ID RUN_ID QUERY [ARGS]`' | ||
| end | ||
|
|
||
| result = Cadence.query_workflow(workflow_class, query, workflow_id, run_id, args) | ||
| puts result.inspect |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| require 'workflows/query_workflow' | ||
| require 'cadence/errors' | ||
|
|
||
|
|
||
| describe QueryWorkflow, :integration do | ||
| subject { described_class } | ||
|
|
||
| it 'returns the correct result for the queries' do | ||
| workflow_id, run_id = run_workflow(described_class) | ||
|
|
||
| # Query with nil workflow class | ||
| expect(Cadence.query_workflow(nil, 'state', workflow_id, run_id)) | ||
| .to eq 'started' | ||
|
|
||
| # Query with arbitrary args | ||
| expect(Cadence.query_workflow(described_class, 'state', workflow_id, run_id, | ||
| 'upcase', 'ignored', 'reverse')) | ||
| .to eq 'DETRATS' | ||
|
|
||
| # Query with no args | ||
| expect(Cadence.query_workflow(described_class, 'signal_count', workflow_id, run_id)) | ||
| .to eq 0 | ||
|
|
||
| # Query with unregistered handler | ||
| expect { Cadence.query_workflow(described_class, 'unknown_query', workflow_id, run_id) } | ||
| .to raise_error(Cadence::QueryFailed, 'Workflow did not register a handler for unknown_query') | ||
|
|
||
| Cadence.signal_workflow(described_class, 'make_progress', workflow_id, run_id) | ||
|
|
||
| # Query for updated signal_count with an unsatisfied reject condition | ||
| expect(Cadence.query_workflow(described_class, 'signal_count', workflow_id, run_id, query_reject_condition: :not_open)) | ||
| .to eq 1 | ||
|
|
||
| Cadence.signal_workflow(described_class, 'finish', workflow_id, run_id) | ||
| wait_for_workflow_completion(workflow_id, run_id) | ||
|
|
||
| # Repeating original query scenarios above, expecting updated state and signal results | ||
| expect(Cadence.query_workflow(nil, 'state', workflow_id, run_id)) | ||
| .to eq 'finished' | ||
|
|
||
| expect(Cadence.query_workflow(described_class, 'state', workflow_id, run_id, | ||
| 'upcase', 'ignored', 'reverse')) | ||
| .to eq 'DEHSINIF' | ||
|
|
||
| expect(Cadence.query_workflow(described_class, 'signal_count', workflow_id, run_id)) | ||
| .to eq 2 | ||
|
|
||
| expect { Cadence.query_workflow(described_class, 'unknown_query', workflow_id, run_id) } | ||
| .to raise_error(Cadence::QueryFailed, 'Workflow did not register a handler for unknown_query') | ||
|
|
||
| # Now that the workflow is completed, test a query with a reject condition satisfied | ||
| expect { Cadence.query_workflow(described_class, 'state', workflow_id, run_id, query_reject_condition: :not_open) } | ||
| .to raise_error(Cadence::QueryFailed, 'Query rejected: status WORKFLOW_EXECUTION_STATUS_COMPLETED') | ||
| 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,36 @@ | ||
| class QueryWorkflow < Cadence::Workflow | ||
| attr_reader :state, :signal_count, :last_signal_received | ||
|
|
||
| def execute | ||
| @state = "started" | ||
| @signal_count = 0 | ||
| @last_signal_received = nil | ||
|
|
||
| workflow.on_query("state") { |*args| apply_transforms(state, args) } | ||
| workflow.on_query("signal_count") { signal_count } | ||
|
|
||
| workflow.on_signal do |signal| | ||
| @signal_count += 1 | ||
| @last_signal_received = signal | ||
| end | ||
|
|
||
| workflow.wait_for { last_signal_received == "finish" } | ||
| @state = "finished" | ||
|
|
||
| { | ||
| signal_count: signal_count, | ||
| last_signal_received: last_signal_received, | ||
| final_state: state | ||
| } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def apply_transforms(value, transforms) | ||
| return value if value.nil? || transforms.empty? | ||
| transforms.inject(value) do |memo, input| | ||
| next memo unless memo.respond_to?(input) | ||
| memo.public_send(input) | ||
| 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
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
Oops, something went wrong.
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.