Skip to content

Tasks changes v2 #341

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

Merged
merged 2 commits into from
Jul 11, 2022
Merged
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
4 changes: 2 additions & 2 deletions lib/meilisearch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def create_dump

### TASKS

def tasks
task_endpoint.task_list
def tasks(options = {})
task_endpoint.task_list(options)
end

def task(task_uid)
Expand Down
9 changes: 7 additions & 2 deletions lib/meilisearch/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

module MeiliSearch
class Task < HTTPRequest
def task_list
http_get '/tasks/'
ALLOWED_PARAMS = [:limit, :from, :index_uid, :type, :status].freeze

def task_list(options = {})
body = Utils.transform_attributes(options.transform_keys(&:to_sym).slice(*ALLOWED_PARAMS))
body = body.transform_values { |v| v.respond_to?(:join) ? v.join(',') : v }

http_get '/tasks/', body
end

def task(task_uid)
Expand Down
6 changes: 3 additions & 3 deletions spec/meilisearch/client/keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
end

it 'updates a key with their uid data' do
new_key = client.create_key(delete_docs_key_options.merge(uid: uuid_v4))
client.create_key(delete_docs_key_options.merge(uid: uuid_v4))
new_updated_key = client.update_key(uuid_v4, name: 'coco')

expect(new_updated_key['name']).to eq('coco')
Expand All @@ -105,9 +105,9 @@
new_key = client.create_key(add_docs_key_options)
client.delete_key(new_key['key'])

expect {
expect do
client.key(new_key['key'])
}.to raise_error(MeiliSearch::ApiError)
end.to raise_error(MeiliSearch::ApiError)
end
end
end
22 changes: 20 additions & 2 deletions spec/meilisearch/client/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
expect(last_task.keys).to include(*succeeded_task_keys)
end

it 'gets a task of the MeiliSearch instance' do
it 'gets a task of the Meilisearch instance' do
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure we will still find this in 2025 😂

task = client.task(0)

expect(task).to be_a(Hash)
expect(task['uid']).to eq(0)
expect(task.keys).to include(*succeeded_task_keys)
end

it 'gets all the tasks of the MeiliSearch instance' do
it 'gets tasks of the Meilisearch instance' do
tasks = client.tasks

expect(tasks['results']).to be_a(Array)
Expand All @@ -42,6 +42,24 @@
expect(last_task.keys).to include(*succeeded_task_keys)
end

it 'paginates tasks with limit/from/next' do
tasks = client.tasks(limit: 2)

expect(tasks['results'].count).to be <= 2
expect(tasks['from']).to be_a(Integer)
expect(tasks['next']).to be_a(Integer)
end

it 'filters tasks with index_uid/type/status' do
tasks = client.tasks(index_uid: ['a-cool-index-name'])

expect(tasks['results'].count).to eq(0)

tasks = client.tasks(index_uid: ['books'], type: ['documentAdditionOrUpdate'], status: ['succeeded'])

expect(tasks['results'].count).to be > 1
end

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