Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Server search #5

wants to merge 13 commits into from

Conversation

bleonard
Copy link
Member

@bleonard bleonard commented Jul 9, 2019

  • 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.

Screen Shot 2019-07-09 at 9 45 40 PM

Copy link
Contributor

@choubacha choubacha left a 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?("{")
Copy link
Contributor

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)
Copy link
Contributor

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.

begin
query_attributes = JSON.parse(query_string)
raise "Not a JSON Object" unless query_attributes.is_a?(Hash)
rescue Exception => e
Copy link
Contributor

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.

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Member Author

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.

@bleonard
Copy link
Member Author

added some specs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants