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 +4 -4
- data/lib/esse/cli/event_listener.rb +26 -0
- data/lib/esse/cli/parser/bool_or_hash.rb +11 -7
- data/lib/esse/events.rb +3 -0
- data/lib/esse/index/indices.rb +7 -2
- data/lib/esse/transport/cluster.rb +12 -4
- data/lib/esse/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b78836cea90af6c95e5bad1fec44c734733e21dab660cbb338a79546f2539d5
|
4
|
+
data.tar.gz: 0d1e073bbcc3ab1576d134ab4c70e2231767b836f59652f2f41b56e5943cc585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
38
|
+
return cast(value) unless ARRAY_SEPARATOR.match?(value)
|
39
39
|
|
40
|
-
value.split(ARRAY_SEPARATOR).map { |v|
|
40
|
+
value.split(ARRAY_SEPARATOR).map { |v| cast(v) }
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
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
|
data/lib/esse/index/indices.rb
CHANGED
@@ -109,8 +109,13 @@ module Esse
|
|
109
109
|
|
110
110
|
task_id = resp['task']
|
111
111
|
task = nil
|
112
|
-
|
113
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
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
|
-
|
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
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.
|
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-
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|