esse 0.4.0.rc3 → 0.4.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dd8f8e268f5c33ed55b160ca803a3d3b4d3c4e7a806b93941b53281325291fb
4
- data.tar.gz: 4b9437a67ff80a09b3951174c60e4658b987f08633dd2ca124fde50cb2cca0b4
3
+ metadata.gz: 1b78836cea90af6c95e5bad1fec44c734733e21dab660cbb338a79546f2539d5
4
+ data.tar.gz: 0d1e073bbcc3ab1576d134ab4c70e2231767b836f59652f2f41b56e5943cc585
5
5
  SHA512:
6
- metadata.gz: c35caa2948ee2c511e4f0171bfd23b92a3ccf6812bcbc4c1f7b007d8e3c42912aa483b1a9baa00b75a54f66de6ad92de1087c4b87d174eab9364931d7a22c3c9
7
- data.tar.gz: 3944a4f0ab6e2b73fe9f52a6dff26b64d1d1ed927f40f7b1eaf42f7b27898b7232c79068cefd9395433838fe8697151b02ccb1166d4d8f4eef186a36729a5881
6
+ metadata.gz: 4118d2d6d2d163456f09c487b391abfb7522d4c1900e1517d94a8414b3f14587abf7e3fbb8292321933c767cb21b981c03f829ec2bd12f4cbc7327aa34cbe3e4
7
+ data.tar.gz: 80cdb7b8ccdb6ca158ca95207b0f9363b3edd19edddc6e9d29c168cb03ae04d520f110c752dd604b19665891cde2ce787db9eb18ca0119d155b90f1150527d38
@@ -102,6 +102,32 @@ module Esse
102
102
  to: colorize(event[:request].dig(:body, :dest, :index), :bold),
103
103
  runtime: formatted_runtime(event[:runtime])
104
104
  end
105
+
106
+ def elasticsearch_task(event)
107
+ running_time_in_nanos = event[:response].dig('task', 'running_time_in_nanos')
108
+ runtime = running_time_in_nanos ? "#{running_time_in_nanos / 1_000_000} ms" : 'unknown'
109
+
110
+ case event[:response]['completed']
111
+ when true
112
+ print_message '[%<runtime>s] Task %<task_id>s successfuly completed. %<total_runtime>s',
113
+ task_id: colorize(event[:request][:id], :bold),
114
+ runtime: formatted_runtime(event[:runtime]),
115
+ total_runtime: colorize("Elapsed time: #{runtime}", :bold)
116
+ when false
117
+ description = event[:response].dig('task', 'description')
118
+ print_message '[%<runtime>s] Task %<task_id>s still in progress: %<description>s. %<total_runtime>s',
119
+ task_id: colorize(event[:request][:id], :bold),
120
+ description: description,
121
+ runtime: formatted_runtime(event[:runtime]),
122
+ total_runtime: colorize("Elapsed time: #{runtime}", :bold)
123
+ end
124
+ end
125
+
126
+ def elasticsearch_cancel_task(event)
127
+ print_message '[%<runtime>s] Task %<task_id>s successfuly canceled',
128
+ task_id: colorize(event[:request][:id], :bold),
129
+ runtime: formatted_runtime(event[:runtime])
130
+ end
105
131
  end
106
132
  end
107
133
  end
@@ -35,16 +35,20 @@ module Esse
35
35
  private
36
36
 
37
37
  def may_array(value)
38
- return may_bool(value) unless ARRAY_SEPARATOR.match?(value)
38
+ return cast(value) unless ARRAY_SEPARATOR.match?(value)
39
39
 
40
- value.split(ARRAY_SEPARATOR).map { |v| may_bool(v) }
40
+ value.split(ARRAY_SEPARATOR).map { |v| cast(v) }
41
41
  end
42
42
 
43
- def may_bool(value)
44
- return true if TRUTHY.include?(value)
45
- return false if FALSEY.include?(value)
46
-
47
- value
43
+ def cast(value)
44
+ case value
45
+ when *TRUTHY then true
46
+ when *FALSEY then false
47
+ when /\A\d+\z/ then value.to_i
48
+ when /\A\d+\.\d+\z/ then value.to_f
49
+ else
50
+ value
51
+ end
48
52
  end
49
53
  end
50
54
  end
data/lib/esse/events.rb CHANGED
@@ -59,5 +59,8 @@ module Esse
59
59
  register_event 'elasticsearch.reindex'
60
60
  register_event 'elasticsearch.update_by_query'
61
61
  register_event 'elasticsearch.delete_by_query'
62
+ register_event 'elasticsearch.tasks'
63
+ register_event 'elasticsearch.task'
64
+ register_event 'elasticsearch.cancel_task'
62
65
  end
63
66
  end
@@ -109,8 +109,13 @@ module Esse
109
109
 
110
110
  task_id = resp['task']
111
111
  task = nil
112
- while (task = cluster.api.task(id: task_id))['completed'] == false
113
- sleep poll_interval
112
+ begin
113
+ while (task = cluster.api.task(id: task_id))['completed'] == false
114
+ sleep poll_interval.to_i
115
+ end
116
+ rescue Interrupt => e
117
+ cluster.api.cancel_task(id: task_id)
118
+ raise e
114
119
  end
115
120
  task
116
121
  end
@@ -40,16 +40,24 @@ module Esse
40
40
  #
41
41
  # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html
42
42
  def tasks(**options)
43
- # coerce_exception { client.perform_request('GET', '/_tasks', options).body }
44
- coerce_exception { client.tasks.list(**options) }
43
+ Esse::Events.instrument('elasticsearch.tasks') do |payload|
44
+ payload[:request] = options
45
+ payload[:response] = coerce_exception { client.tasks.list(**options) }
46
+ end
45
47
  end
46
48
 
47
49
  def task(id:, **options)
48
- coerce_exception { client.tasks.get(task_id: id, **options) }
50
+ Esse::Events.instrument('elasticsearch.task') do |payload|
51
+ payload[:request] = { id: id }.merge(options)
52
+ payload[:response] = coerce_exception { client.tasks.get(task_id: id, **options) }
53
+ end
49
54
  end
50
55
 
51
56
  def cancel_task(id:, **options)
52
- coerce_exception { client.tasks.cancel(task_id: id, **options) }
57
+ Esse::Events.instrument('elasticsearch.cancel_task') do |payload|
58
+ payload[:request] = { id: id }.merge(options)
59
+ payload[:response] = coerce_exception { client.tasks.cancel(task_id: id, **options) }
60
+ end
53
61
  end
54
62
  end
55
63
 
data/lib/esse/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Esse
4
- VERSION = '0.4.0.rc3'
4
+ VERSION = '0.4.0.rc4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.rc3
4
+ version: 0.4.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos G. Zimmermann
8
8
  autorequire:
9
9
  bindir: exec
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2024-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json