Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,5 @@ distinct_attribute_guide_distinct_parameter_1: |-
client.index('products').search('white shirt', {
distinct: 'sku'
})
get_task_documents_1: |-
client.task_documents(1)
10 changes: 10 additions & 0 deletions lib/meilisearch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ def task(task_uid)
task_endpoint.task(task_uid)
end

# Get task's document payload
#
# Retrieve the document payload that was sent with this task. Only available for document-related tasks that are enqueued or processing.
#
# @param task_uid [String] uid of the requested task
# @return [String] The content of the task update
def task_documents(task_uid)
task_endpoint.task_documents(task_uid)
end

# Wait for a task in a busy loop.
#
# Try to avoid using it. Wrapper around {Task#wait_for_task}.
Expand Down
9 changes: 5 additions & 4 deletions lib/meilisearch/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ def task_list(options = {})
def task(task_uid)
http_get "/tasks/#{task_uid}"
end
alias index_task task

def index_tasks(index_uid)
http_get '/tasks', { indexUids: [index_uid].flatten.join(',') }
def task_documents(task_uid)
http_get "/tasks/#{task_uid}/documents"
end

def index_task(task_uid)
http_get "/tasks/#{task_uid}"
def index_tasks(index_uid)
http_get '/tasks', { indexUids: [index_uid].flatten.join(',') }
end

def cancel_tasks(options)
Expand Down
14 changes: 14 additions & 0 deletions spec/meilisearch/client/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@
)
end

it 'gets all the documents from a task' do
client.update_experimental_features(getTaskDocumentsRoute: true)

document_to_insert = { objectId: 123, title: 'Pride and Prejudice', comment: 'A great book' }

task = index.add_documents(document_to_insert)
documents = client.task_documents(task.metadata['uid'])

expect(documents).to be_a(String)
expect(documents).to eq('{"objectId":123,"title":"Pride and Prejudice","comment":"A great book"}')

client.update_experimental_features(getTaskDocumentsRoute: false)
end
Comment thread
Nymuxyzo marked this conversation as resolved.

describe '#index.wait_for_task' do
it 'waits for task with default values' do
task = index.add_documents(documents)
Expand Down