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

Implement wait_for_pending_update method #43

Merged
merged 3 commits into from Jun 4, 2020

Conversation

eskombro
Copy link
Member

@eskombro eskombro commented Jun 2, 2020

Based on this discussion, SDKs must provide a method that waits synchronously for an update to be processed by MeiliSearch.

Parameters:

  • update_id: id of the update to be waited

Optional parameters:

  • timeout_in_ms max number of millisecond this method should wait before rising a TimeoutError (default=2000ms)
  • interval_in_ms number of millisecond to set an interval of time this method should wait (sleep) between requests (default=10ms)

tests

  • Added wait_for_pending_update method in the Index class
  • Added tests for default values, test for timeout and test for interval.

Closes #25

@eskombro eskombro self-assigned this Jun 2, 2020
- Implement wait_for_pending_update method
- Add tests for wait_for_pending_update
@eskombro eskombro force-pushed the implement_wait_for_pending_update branch from 850adaa to d013e2d Compare June 3, 2020 00:11
@eskombro eskombro marked this pull request as ready for review June 3, 2020 00:12
@eskombro eskombro requested a review from a team June 3, 2020 00:12
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!


module MeiliSearch
class Index < HTTPRequest
class Index < HTTPRequest # rubocop:disable Metrics/ClassLength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With rubocop we chose not to use this kind of line in the code: we use the .rubocop_todo.yml file instead. This file is autogenerated.
When you're done with the linter errors (I mean, when all the remaining errors are acceptable for you) you can generated the file with the command bundle exec rubocop --auto-gen-config.
Stripe uses it the same way 😉
https://github.com/stripe/stripe-ruby/blob/52f64b2bacf6caa23dba15cf43b723075c14d133/.rubocop_todo.yml

Copy link
Member

@curquiza curquiza Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an obvious way for new users, I'm going to add some explanation in the README 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@@ -231,5 +232,16 @@ def accept_new_fields
def update_accept_new_fields(accept_new_fields)
http_post "/indexes/#{@uid}/settings/accept-new-fields", accept_new_fields
end

def wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this method in the ### UPDATES part, and not at the end of this file?

@@ -231,5 +232,16 @@ def accept_new_fields
def update_accept_new_fields(accept_new_fields)
http_post "/indexes/#{@uid}/settings/accept-new-fields", accept_new_fields
end

def wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
Timeout.timeout(timeout_in_ms.to_f / 1000) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather throw a custom MeiliSearch Exception so that the user knows it comes from MeiliSearch. You have to add an error in the error.rb file.
We do the same in JS and PHP for example:

(I realized we didn't do that for the python, we have to fix that, but it's normal because when we created this method, the error handler didn't exist ^^)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did implement a custom error, also with a custom message, let me know what do you think :)

@eskombro eskombro requested a review from curquiza June 3, 2020 17:46
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!!! 👌
Here is a new ruby developer in the team 😉
Merging...

@curquiza curquiza merged commit 7f4cd43 into master Jun 4, 2020
@curquiza curquiza deleted the implement_wait_for_pending_update branch June 4, 2020 06:40
bidoubiwa pushed a commit that referenced this pull request Mar 8, 2021
* Wait for pending update method

- Implement wait_for_pending_update method
- Add tests for wait_for_pending_update

* Lint auto-generated file

* Custom error
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.

wait_for_pending_update method
2 participants