jay_api 29.5.0 → 29.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f997e23215ab5ee73c077534d19889c9b91ae5c877a77859b75f454e555bb105
4
- data.tar.gz: f0250fc57649d863fde276f3e753b9d8aecff90c0bd286a1a97fb12b447b1c33
3
+ metadata.gz: a1cec24f42607c2e94f600045f41f8c5db2593ebd478f391f9c97786d139b819
4
+ data.tar.gz: f35ecb6ce96aa5215d3a97229e4ee497697b57daa2ffa36b607d5d4d88a7bb3d
5
5
  SHA512:
6
- metadata.gz: bf6ba31a0f5960479de755757d6479b0c9373cc4b4e9e99ee55d853ba90417d1161b02d88d2103d8c86cd13a028f725293c3f13422c0422c51e0d64b6a906a40
7
- data.tar.gz: ad81742c20b6a93b973972ee49b814ea61b3ecaac8ce0945aceac05dbd8020ec2c9d4dca701c261dadc7eeffbb3e40658ba6476ba015662217e0a8509785235f
6
+ metadata.gz: afe9866d1912c2323ed2ff5e4c19d72928a1403a406cfbbca11e479a8c61dd4e877c68f0ad5ed9f9b25e002f84f510852161316d1c7fc669c9935c5262742e55
7
+ data.tar.gz: 9487900e069641c26048da4f4979f3d07ea6873f258e8e8025d0033bf441d4a6c98ee1941060273a6f621e1709fda60c73cd7745c63dba7f0dc0531406e4fa98
data/CHANGELOG.md CHANGED
@@ -8,6 +8,18 @@ Please mark backwards incompatible changes with an exclamation mark at the start
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [29.6.0] - 2026-03-16
12
+
13
+ ### Deprecated
14
+ - The `#task_by_id` method of the `Elasticsearch::Client` class.
15
+
16
+ ### Added
17
+ - The `#all` method to `JayAPI::Elasticsearch::Tasks`. The method returns the
18
+ status of all running tasks on the Elasticsearch cluster.
19
+ - The `#tasks` method to `JayAPI::Elasticsearch::Client`. The method returns an
20
+ instance of `JayAPI::Elasticsearch::Tasks`, which gives the user access to the
21
+ status of the tasks running on the Elasticsearch cluster.
22
+
11
23
  ## [29.5.0] - 2026-02-23
12
24
 
13
25
  ### Fixed
@@ -1,39 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'timeout'
4
- require 'elasticsearch/transport/transport/errors'
5
4
  require 'faraday/error'
6
5
  require 'forwardable'
7
6
 
8
- require_relative '../abstract/connection'
7
+ require_relative 'mixins/retriable_requests'
9
8
  require_relative 'stats'
9
+ require_relative 'tasks'
10
10
 
11
11
  module JayAPI
12
12
  module Elasticsearch
13
- # The JayAPI wrapper class over the Elastisearch::Client object. It mirrors
13
+ # The JayAPI wrapper class over the +Elasticsearch::Client+ object. It mirrors
14
14
  # the object's API, but if one of the ERRORS is raised, this Wrapper class will
15
15
  # rescue the error up to a few times and re-try the connection. This way the
16
16
  # connection to Elasticsearch will be more robust.
17
17
  class Client
18
18
  extend Forwardable
19
19
 
20
- # The errors that, if raised, must cause a retry of the connection.
21
- ERRORS = [
22
- ::Elasticsearch::Transport::Transport::ServerError,
23
- Faraday::TimeoutError
24
- ].freeze
25
-
26
- # Subclasses of the +Elasticsearch::Transport::Transport::ServerError+
27
- # for which a retry doesn't make sense.
28
- NON_RETRIABLE_ERRORS = [
29
- ::Elasticsearch::Transport::Transport::Errors::BadRequest,
30
- ::Elasticsearch::Transport::Transport::Errors::Unauthorized,
31
- ::Elasticsearch::Transport::Transport::Errors::Forbidden,
32
- ::Elasticsearch::Transport::Transport::Errors::NotFound,
33
- ::Elasticsearch::Transport::Transport::Errors::MethodNotAllowed,
34
- ::Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge,
35
- ::Elasticsearch::Transport::Transport::Errors::NotImplemented
36
- ].freeze
20
+ include JayAPI::Elasticsearch::Mixins::RetriableRequests
37
21
 
38
22
  attr_reader :transport_client, :logger, :max_attempts, :wait_strategy
39
23
 
@@ -88,6 +72,7 @@ module JayAPI
88
72
  # parameters. If the request fails, additional retries will be performed.
89
73
  # @see Elasticsearch::Client#tasks for more info about the arguments and
90
74
  # the return value.
75
+ # @deprecated Use Tasks#by_id instead.
91
76
  def task_by_id(**args)
92
77
  retry_request { transport_client.tasks.get(**args) }
93
78
  end
@@ -98,13 +83,11 @@ module JayAPI
98
83
  @stats ||= ::JayAPI::Elasticsearch::Stats.new(transport_client)
99
84
  end
100
85
 
101
- private
102
-
103
- # @param [Proc] block The block to execute.
104
- # @yieldreturn [Object] Whatever the block returns
105
- def retry_request(&block)
106
- Abstract::Connection.new(max_attempts: max_attempts, wait_strategy: wait_strategy.dup, logger: logger)
107
- .retry(errors: ERRORS, except: NON_RETRIABLE_ERRORS, &block)
86
+ # @return [JayAPI::Elasticsearch::Tasks] An instance of the +Tasks+ class,
87
+ # which can be used to retrieve the status of the tasks running on the
88
+ # Elasticsearch cluster.
89
+ def tasks
90
+ @tasks ||= ::JayAPI::Elasticsearch::Tasks.new(client: self)
108
91
  end
109
92
  end
110
93
  end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'elasticsearch/transport/transport/errors'
4
+
5
+ require_relative '../../abstract/connection'
6
+
7
+ module JayAPI
8
+ module Elasticsearch
9
+ module Mixins
10
+ # A mixin that allows the including class to retry requests to
11
+ # Elasticsearch by leveraging the +Abstract::Connection+ class'
12
+ # capabilities.
13
+ module RetriableRequests
14
+ # The errors that, if raised, must cause a retry of the connection.
15
+ RETRIABLE_ERRORS = [
16
+ ::Elasticsearch::Transport::Transport::ServerError,
17
+ Faraday::TimeoutError
18
+ ].freeze
19
+
20
+ # Subclasses of the +Elasticsearch::Transport::Transport::ServerError+
21
+ # for which a retry doesn't make sense.
22
+ NON_RETRIABLE_ERRORS = [
23
+ ::Elasticsearch::Transport::Transport::Errors::BadRequest,
24
+ ::Elasticsearch::Transport::Transport::Errors::Unauthorized,
25
+ ::Elasticsearch::Transport::Transport::Errors::Forbidden,
26
+ ::Elasticsearch::Transport::Transport::Errors::NotFound,
27
+ ::Elasticsearch::Transport::Transport::Errors::MethodNotAllowed,
28
+ ::Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge,
29
+ ::Elasticsearch::Transport::Transport::Errors::NotImplemented
30
+ ].freeze
31
+
32
+ # @return [Integer] The maximum number of times a request should be
33
+ # retried before giving up.
34
+ def max_attempts
35
+ raise_not_implemented(__method__)
36
+ end
37
+
38
+ # @return [JayAPI::Elasticsearch::WaitStrategy] The waiting strategy for
39
+ # retries.
40
+ def wait_strategy
41
+ raise_not_implemented(__method__)
42
+ end
43
+
44
+ # @return [Logging::Logger] A logger to log messages.
45
+ def logger
46
+ raise_not_implemented(__method__)
47
+ end
48
+
49
+ # @return [Array<Class>] The array of errors that, if raised, must cause
50
+ # a retry of the request.
51
+ def retriable_errors
52
+ RETRIABLE_ERRORS
53
+ end
54
+
55
+ # @return [Array<Class>] An array of subclasses of the
56
+ # +Elasticsearch::Transport::Transport::ServerError+ for which a retry
57
+ # doesn't make sense.
58
+ def non_retriable_errors
59
+ NON_RETRIABLE_ERRORS
60
+ end
61
+
62
+ private
63
+
64
+ # Uses the +Abstract::Connection+ class to retry the request enclosed in
65
+ # the given block.
66
+ def retry_request(&)
67
+ Abstract::Connection.new(max_attempts:, wait_strategy: wait_strategy.dup, logger:)
68
+ .retry(errors: retriable_errors, except: non_retriable_errors, &)
69
+ end
70
+
71
+ # @raise [NotImplementedError] Is always raised with the appropriate
72
+ # error message.
73
+ def raise_not_implemented(method)
74
+ raise NotImplementedError, "Please implement the method ##{method} in #{self.class}"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mixins/retriable_requests'
4
+
5
+ module JayAPI
6
+ module Elasticsearch
7
+ # A namespace for Elasticsearch related mixins.
8
+ module Mixins; end
9
+ end
10
+ end
@@ -1,22 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support'
4
+ require 'active_support/core_ext/enumerable'
4
5
  require 'active_support/core_ext/hash/indifferent_access'
6
+ require 'forwardable'
7
+
8
+ require_relative 'mixins/retriable_requests'
5
9
 
6
10
  module JayAPI
7
11
  module Elasticsearch
8
12
  # Represents Elasticsearch tasks. Returns information about the tasks
9
13
  # currently executing in the cluster.
10
- # TODO: Add #all [JAY-593]
11
14
  class Tasks
15
+ extend Forwardable
16
+ include ::JayAPI::Elasticsearch::Mixins::RetriableRequests
17
+
12
18
  attr_reader :client
13
19
 
20
+ def_delegators :client, :transport_client, :max_attempts, :wait_strategy, :logger
21
+
14
22
  # @param [JayAPI::Elasticsearch::Client] client The Elasticsearch Client
15
23
  # object
16
24
  def initialize(client:)
17
25
  @client = client
18
26
  end
19
27
 
28
+ # Gets the list of tasks running on the Elasticsearch cluster.
29
+ # For more information about this endpoint and the parameters please see:
30
+ # https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-tasks-list
31
+ # @param [Array<String>] actions A list of actions. Only tasks matching
32
+ # these actions will be returned, if no task matches the result will be
33
+ # empty.
34
+ # @param [Boolean] detailed Whether or not the result should include task
35
+ # details or not.
36
+ # @return [Hash] A hash with the list of tasks running on the
37
+ # Elasticsearch cluster.
38
+ def all(actions: nil, detailed: false)
39
+ # Needed because unlike many Elasticsearch methods Tasks#list doesn't
40
+ # call #listify over +actions+.
41
+ actions = actions&.then do |value|
42
+ value.is_a?(Array) ? value.join(',') : value
43
+ end
44
+
45
+ retry_request do
46
+ tasks_client.list({ actions:, detailed: }.compact_blank)
47
+ end
48
+ end
49
+
20
50
  # Retrieves info about the task with the passed +task_id+
21
51
  # For more information on how to build the query please refer to the
22
52
  # Elasticsearch DSL documentation:
@@ -29,7 +59,17 @@ module JayAPI
29
59
  # @raise [Elasticsearch::Transport::Transport::ServerError] If the
30
60
  # query fails.
31
61
  def by_id(task_id)
32
- client.task_by_id(task_id: task_id, wait_for_completion: true).deep_symbolize_keys
62
+ retry_request do
63
+ tasks_client.get(task_id:, wait_for_completion: true).deep_symbolize_keys
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ # @return [Elasticsearch::API::Tasks::TasksClient] The client used to
70
+ # access tasks-related information.
71
+ def tasks_client
72
+ @tasks_client ||= transport_client.tasks
33
73
  end
34
74
  end
35
75
  end
@@ -8,6 +8,7 @@ require_relative 'elasticsearch/errors'
8
8
  require_relative 'elasticsearch/index'
9
9
  require_relative 'elasticsearch/indexes'
10
10
  require_relative 'elasticsearch/indices'
11
+ require_relative 'elasticsearch/mixins'
11
12
  require_relative 'elasticsearch/query_builder'
12
13
  require_relative 'elasticsearch/query_results'
13
14
  require_relative 'elasticsearch/response'
@@ -2,5 +2,5 @@
2
2
 
3
3
  module JayAPI
4
4
  # JayAPI gem's semantic version
5
- VERSION = '29.5.0'
5
+ VERSION = '29.6.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jay_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 29.5.0
4
+ version: 29.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Accenture-Industry X
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-02-23 00:00:00.000000000 Z
12
+ date: 2026-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -135,6 +135,8 @@ files:
135
135
  - lib/jay_api/elasticsearch/indices.rb
136
136
  - lib/jay_api/elasticsearch/indices/settings.rb
137
137
  - lib/jay_api/elasticsearch/indices/settings/blocks.rb
138
+ - lib/jay_api/elasticsearch/mixins.rb
139
+ - lib/jay_api/elasticsearch/mixins/retriable_requests.rb
138
140
  - lib/jay_api/elasticsearch/query_builder.rb
139
141
  - lib/jay_api/elasticsearch/query_builder/aggregations.rb
140
142
  - lib/jay_api/elasticsearch/query_builder/aggregations/aggregation.rb
@@ -225,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
227
  - !ruby/object:Gem::Version
226
228
  version: '0'
227
229
  requirements: []
228
- rubygems_version: 3.3.27
230
+ rubygems_version: 3.4.19
229
231
  signing_key:
230
232
  specification_version: 4
231
233
  summary: A collection of classes and modules to access JAY's functionality