-
Notifications
You must be signed in to change notification settings - Fork 7
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
Server search #5
base: master
Are you sure you want to change the base?
Conversation
bleonard
commented
Jul 9, 2019
•
edited
Loading
edited
- adds capability to "Bus" tab to give a sample event and see what subscriptions will run.
- also puts subscription key in there to match it up to code better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really great feature and tool! :)
I think before merging we should add some specs around the parsing of the query itself. That way we have examples that demonstrate and validate common inputs.
class Helpers | ||
class << self | ||
def parse_query(query_string) | ||
has_open_brace = query_string.include?("{") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's generally a flat JSON, but perhaps we could use a regex here to anchor the opening and closing brace to the start and end? I think we could also strip the string and then look at the first and last character.
# first let's see if it parses | ||
begin | ||
query_attributes = JSON.parse(query_string) | ||
raise "Not a JSON Object" unless query_attributes.is_a?(Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could also just set the exception variable here. That would avoid the raise and immediate rescue.
lib/resque_bus/server.rb
Outdated
begin | ||
query_attributes = JSON.parse(query_string) | ||
raise "Not a JSON Object" unless query_attributes.is_a?(Hash) | ||
rescue Exception => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't rescue Exception
as that include out of memory errors and other system errors. We should either target StandardError
by omitting it, or rescue JSON parse errors specifically.
lib/resque_bus/server.rb
Outdated
if query_attributes | ||
# it parsed but it's something else | ||
if query_attributes.is_a?(Array) && query_attributes.length == 1 | ||
# maybe it's the thing from the queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you expand this comment to explain what "the thing from the queue" is? It sounds like a horror movie.
# maybe it's the thing from the queue | ||
json_string = query_attributes.first | ||
fixed = JSON.parse(json_string) rescue nil | ||
return fixed if fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we validate that this is also a Hash as we do earlier?
|
||
if !has_open_brace && !has_close_brace | ||
# maybe they just forgot the braces | ||
fixed = JSON.parse("{ #{query_string} }") rescue nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we do this on line 38 before we parse? If we're concerned about the possibility that it's an array, maybe we can also look at the opening/closing brackets to see if they are square braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I tried to do was not mess with the input if it would parse. That's why I parsed first. Seems like a safe practice - if they put something that works use it before messing around with it.
return fixed if fixed | ||
end | ||
|
||
if !has_open_brace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be able to reduce the complexity. of these conditions:
query_string = "{ #{query_string}" unless has_open_brace
query_string = "#{query_string} }" unless has_close_brace
fixed = JSON.parse(query_string) rescue nil
return fixed if fixed
if query_string.length > 0 | ||
begin | ||
query_attributes = ::ResqueBus::Server::Helpers.parse_query(query_string) | ||
raise "Not a JSON Object" unless query_attributes.is_a?(Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make the view lighter if we put this logic into the parser. This is already repeated with some of the logic in the parse_query
fuction.
|
||
class Helpers | ||
class << self | ||
def parse_query(query_string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this move to QueueBus so that it can be shared between sidekiq-bus and resque-bus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like a plan to me.
added some specs. |