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 delete_tasks method #394

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/meilisearch/client.rb
Expand Up @@ -126,6 +126,10 @@ def cancel_tasks(options = {})
task_endpoint.cancel_tasks(options)
end

def delete_tasks(options = {})
task_endpoint.delete_tasks(options)
end

def tasks(options = {})
task_endpoint.task_list(options)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/meilisearch/http_request.rb
Expand Up @@ -73,11 +73,12 @@ def http_patch(relative_path = '', body = nil, query_params = nil)
)
end

def http_delete(relative_path = '')
def http_delete(relative_path = '', query_params = nil)
send_request(
proc { |path, config| self.class.delete(path, config) },
relative_path,
config: {
query_params: query_params,
headers: remove_headers(@headers.dup, 'Content-Type'),
options: @options
}
Expand Down
4 changes: 4 additions & 0 deletions lib/meilisearch/task.rb
Expand Up @@ -32,6 +32,10 @@ def cancel_tasks(options)
http_post '/tasks/cancel', nil, Utils.parse_query(options, ALLOWED_CANCELATION_PARAMS)
end

def delete_tasks(options)
http_delete '/tasks', Utils.parse_query(options, ALLOWED_CANCELATION_PARAMS)
end

def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
Timeout.timeout(timeout_in_ms.to_f / 1000) do
loop do
Expand Down
32 changes: 31 additions & 1 deletion spec/meilisearch/client/tasks_spec.rb
Expand Up @@ -177,9 +177,39 @@
task = client.cancel_tasks(uids: [1, 2])
task = client.wait_for_task(task['taskUid'])

expect(task['details']['originalFilters']).to eq('uids=1%2C2')
expect(task['details']['originalFilter']).to eq('?uids=1%2C2')
expect(task['details']['matchedTasks']).to be_a(Integer)
expect(task['details']['canceledTasks']).to be_a(Integer)
end
end

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

client.delete_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

it 'has fields in the details field' do
task = client.delete_tasks(uids: [1, 2])
task = client.wait_for_task(task['taskUid'])

expect(task['details']['originalFilter']).to eq('?uids=1%2C2')
expect(task['details']['matchedTasks']).to be_a(Integer)
expect(task['details']['deletedTasks']).to be_a(Integer)
end
end
end