Class: MeiliSearch::Task

Inherits:
HTTPRequest show all
Defined in:
lib/meilisearch/task.rb

Constant Summary collapse

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
ALLOWED_CANCELATION_PARAMS =
(ALLOWED_PARAMS - [:limit, :from]).freeze

Constants inherited from HTTPRequest

HTTPRequest::DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from HTTPRequest

#headers, #options

Instance Method Summary collapse

Methods inherited from HTTPRequest

#http_delete, #http_get, #http_patch, #http_post, #http_put, #initialize

Constructor Details

This class inherits a constructor from MeiliSearch::HTTPRequest

Instance Method Details

#cancel_tasks(options) ⇒ Object



31
32
33
# File 'lib/meilisearch/task.rb', line 31

def cancel_tasks(options)
  http_post '/tasks/cancel', nil, Utils.parse_query(options, ALLOWED_CANCELATION_PARAMS)
end

#delete_tasks(options) ⇒ Object



35
36
37
# File 'lib/meilisearch/task.rb', line 35

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

#index_task(task_uid) ⇒ Object



27
28
29
# File 'lib/meilisearch/task.rb', line 27

def index_task(task_uid)
  http_get "/tasks/#{task_uid}"
end

#index_tasks(index_uid) ⇒ Object



23
24
25
# File 'lib/meilisearch/task.rb', line 23

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

#task(task_uid) ⇒ Object



19
20
21
# File 'lib/meilisearch/task.rb', line 19

def task(task_uid)
  http_get "/tasks/#{task_uid}"
end

#task_list(options = {}) ⇒ Object



15
16
17
# File 'lib/meilisearch/task.rb', line 15

def task_list(options = {})
  http_get '/tasks/', Utils.parse_query(options, ALLOWED_PARAMS)
end

#wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/meilisearch/task.rb', line 39

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
      task = task(task_uid)
      return task if achieved_task?(task)

      sleep interval_in_ms.to_f / 1000
    end
  end
rescue Timeout::Error
  raise MeiliSearch::TimeoutError
end