-
Notifications
You must be signed in to change notification settings - Fork 46
Wait for Asynchronous Tasks
Some Meilisearch operations are asynchronous, e.g. the document addition or the settings update. They will be put in a queue and will be executed in turn (asynchronously).
More about the asynchronous tasks of Meilisearch
You might need to wait for the complete execution of this task before executing the rest of your code.
🚨 The following methods should not be used in production!
The wait_for_task
method makes the task synchronous:
def wait_for_task(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
With wait_for_task
:
puts 'Adding Le Petit Prince...'
response = index.add_document(id: 1, title: 'Le Petit Prince')
task_uid = response['uid']
wait_for_task(task_uid)
puts 'Addition done!'
Adding Le Petit Prince...
[Meilisearch has finished adding the document]
Addition done!
Without wait_for_task
:
puts 'Adding Le Petit Prince...'
response = index.add_document(id: 1, title: 'Le Petit Prince')
puts 'Addition done!'
Adding Le Petit Prince...
Addition done!
[Meilisearch has now finished adding the document, but not before the "Addition done!" was written]
This library provides the following synchronous methods:
add_documents!
update_documents!
delete_documents!
delete_document!
delete_all_documents!
These methods stop your code execution until the asynchronous task has been processed by Meilisearch.