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

Add update filter for tasks #391

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
8 changes: 6 additions & 2 deletions lib/meilisearch/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

module MeiliSearch
class Task < HTTPRequest
ALLOWED_PARAMS = [:limit, :from, :index_uid, :type, :status].freeze
ALLOWED_PARAMS = [
:limit, :from, :index_uids, :types, :statuses, :uids, :canceled_by,
:before_enqueued_at, :after_enqueued_at, :before_started_at, :after_started_at,
:before_finished_at, :after_finished_at
].freeze

def task_list(options = {})
body = Utils.transform_attributes(options.transform_keys(&:to_sym).slice(*ALLOWED_PARAMS))
Expand All @@ -19,7 +23,7 @@ def task(task_uid)
end

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

def index_task(task_uid)
Expand Down
25 changes: 22 additions & 3 deletions spec/meilisearch/client/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,35 @@
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'])
it 'filters tasks with index_uids/types/statuses' do
tasks = client.tasks(index_uids: ['a-cool-index-name'])

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

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

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

it 'ensures supports to all available filters' do
allow(MeiliSearch::Utils).to receive(:transform_attributes).and_call_original

client.tasks(
canceled_by: [1, 2], uids: [2], foo: 'bar',
before_enqueued_at: '2022-01-20', after_enqueued_at: '2022-01-20',
before_started_at: '2022-01-20', after_started_at: '2022-01-20',
before_finished_at: '2022-01-20', after_finished_at: '2022-01-20'
)

expect(MeiliSearch::Utils).to have_received(:transform_attributes)
.with(
canceled_by: [1, 2], uids: [2],
before_enqueued_at: '2022-01-20', after_enqueued_at: '2022-01-20',
before_started_at: '2022-01-20', after_started_at: '2022-01-20',
before_finished_at: '2022-01-20', after_finished_at: '2022-01-20'
)
end

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