-
Notifications
You must be signed in to change notification settings - Fork 73
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
Introduce Multi Cluster Management #285
Conversation
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.
LGTM, just minor Ruby syntax 🙌 👍
lib/algolia/client.rb
Outdated
delete(Protocol.cluster_mapping_uri, :write, request_options) | ||
end | ||
|
||
def search_user_id(query, clusterName = nil, page = nil, hits_per_page = nil, request_options = {}) |
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.
=> clusterName
cluster_name
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.
Old habit :D
lib/algolia/client.rb
Outdated
end | ||
|
||
def search_user_id(query, clusterName = nil, page = nil, hits_per_page = nil, request_options = {}) | ||
body = {:query => query} |
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.
{:query => query} => { :query => query }
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.
BTW I didn't mark all of them, just one example
lib/algolia/protocol.rb
Outdated
|
||
def Protocol.cluster_mapping_uri(user_id = nil) | ||
if user_id | ||
user_id = "/#{CGI.escape(user_id)}" |
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.
Usually inlined if
are written after the statement in Ruby: user_id = "/#{CGI.escape(user_id)}" if user_id
lib/algolia/protocol.rb
Outdated
if user_id | ||
user_id = "/#{CGI.escape(user_id)}" | ||
end | ||
"/#{VERSION}/clusters/mapping" + user_id.to_s |
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.
Is this endpoint valid /#{VERSION}/clusters/mapping
if user_id is 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.
Yes, it's use to add/remove user IDs, I didn't want to create 2 entries in Protocol but maybe that would be clearer.
spec/client_mcm_spec.rb
Outdated
end | ||
|
||
after(:all) do | ||
# @index.delete_index rescue "not fatal" |
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.
|
||
it "should remove a user_id" do | ||
res = @client.remove_user_id(@user_id) | ||
sleep(2) |
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.
There is no waitTask
for MCM?
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.
No :(
A better way to do this would be to loop and call multiple times to see if it was removed. After X attemps, the test would fail.
lib/algolia/client.rb
Outdated
end | ||
|
||
def assign_user_id(user_id, cluster_name, request_options = {}) | ||
if !request_options["headers"].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.
You can use single quotes when there is no interpolation to perform
spec/spec_helper.rb
Outdated
@@ -26,6 +26,7 @@ | |||
|
|||
RSpec.configure do |config| | |||
config.mock_with :rspec | |||
config.expect_with(:rspec) { |c| c.syntax = :should } |
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.
Oh my bad, since it is currently working with expect
for the oldest Ruby version already, I think it's not necessary to downgrade the syntax
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 understood this opposite. I thought expect
was the new way and we were using include
for older version. I had a warning saying it should be activated explicitely. I'll check again 👌
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.
You are right, it's the new way but it is working for old rubies; Take a look at the latest Travis run, all green even on 1.8.xx
lib/algolia/client.rb
Outdated
end | ||
|
||
def remove_user_id(user_id, request_options = {}) | ||
if !request_options["headers"].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.
We could factorize it
@raphi Let me know what you think of the 3rd commit. |
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.
You should either add the exclamation mark to your method add_header_to_request_options!
to indicate you are modifying the object passed (call to merge!
) and then you don't need the variable assignment or use merge
in your method
Updated! Thanks for review |
@julienbourdeau np! Please just revert |
d117a9a
to
bda8214
Compare
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.
LGTM 👍
Build is greed ✅ |
@julienbourdeau what did you changed though? It seems there might be some concurrency issues in the MCM tests |
I think when they run all at once, the delay might be a bit longer to assign/remove user ids but the name shouldn't collide. |
I don't remember the error exactly but on top of my head it was something like "MCM already processing id whatever" so probably a delay issue. |
Yes, I think it was occuring when trying to remove a user id while the assigning task wasn't finished. There is no taskID for this type of job :( |
Related PR:
Doc snippets are coming