Class: JayAPI::Elasticsearch::Tasks

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Mixins::RetriableRequests
Defined in:
lib/jay_api/elasticsearch/tasks.rb

Overview

Represents Elasticsearch tasks. Returns information about the tasks currently executing in the cluster.

Constant Summary

Constants included from Mixins::RetriableRequests

Mixins::RetriableRequests::NON_RETRIABLE_ERRORS, Mixins::RetriableRequests::RETRIABLE_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::RetriableRequests

#logger, #max_attempts, #non_retriable_errors, #retriable_errors, #wait_strategy

Constructor Details

#initialize(client:) ⇒ Tasks

Returns a new instance of Tasks.

Parameters:



24
25
26
# File 'lib/jay_api/elasticsearch/tasks.rb', line 24

def initialize(client:)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



18
19
20
# File 'lib/jay_api/elasticsearch/tasks.rb', line 18

def client
  @client
end

Instance Method Details

#all(actions: nil, detailed: false) ⇒ Hash

Gets the list of tasks running on the Elasticsearch cluster. For more information about this endpoint and the parameters please see: www.elastic.co/docs/api/doc/elasticsearch/operation/operation-tasks-list

Parameters:

  • actions (Array<String>) (defaults to: nil)

    A list of actions. Only tasks matching these actions will be returned, if no task matches the result will be empty.

  • detailed (Boolean) (defaults to: false)

    Whether or not the result should include task details or not.

Returns:

  • (Hash)

    A hash with the list of tasks running on the Elasticsearch cluster.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jay_api/elasticsearch/tasks.rb', line 38

def all(actions: nil, detailed: false)
  # Needed because unlike many Elasticsearch methods Tasks#list doesn't
  # call #listify over +actions+.
  actions = actions&.then do |value|
    value.is_a?(Array) ? value.join(',') : value
  end

  retry_request do
    tasks_client.list({ actions:, detailed: }.compact_blank)
  end
end

#by_id(task_id) ⇒ Hash

Retrieves info about the task with the passed task_id For more information on how to build the query please refer to the Elasticsearch DSL documentation: www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html#tasks-api-query-params

Examples:

Returned Hash can be found in this method’s unit tests

Parameters:

  • task_id (String)

    The ID of the task whose info is needed

Returns:

  • (Hash)

    A Hash that details the results of the operation defined by task_id

Raises:

  • (Elasticsearch::Transport::Transport::ServerError)

    If the query fails.



61
62
63
64
65
# File 'lib/jay_api/elasticsearch/tasks.rb', line 61

def by_id(task_id)
  retry_request do
    tasks_client.get(task_id:, wait_for_completion: true).deep_symbolize_keys
  end
end