Module: Esse::CLI::EventListener
- Extended by:
- Output
- Defined in:
- lib/esse/cli/event_listener.rb
Class Method Summary
collapse
Methods included from Output
colorize, formatted_runtime, print_backtrace, print_error, print_message, runtime_padding
Class Method Details
.[](event_name) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/esse/cli/event_listener.rb', line 12
def [](event_name)
method_name = Hstring.new(event_name).underscore.to_sym
return unless respond_to?(method_name)
method(method_name)
end
|
.elasticsearch_bulk(event) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/esse/cli/event_listener.rb', line 86
def elasticsearch_bulk(event)
print_message('[%<runtime>s] Bulk index %<name>s%<type>s%<wait_interval>s: ',
runtime: formatted_runtime(event[:runtime]),
name: colorize(event[:request][:index], :bold),
type: (event[:request][:type] ? " for type #{colorize(event[:request][:type], :bold)}" : ''),
wait_interval: (event[:wait_interval].nonzero? ? " (wait interval #{event[:wait_interval]}s)" : ''),
newline: false,)
stats = event[:body_stats].select { |_, v| v.nonzero? }.map do |type, count|
"#{colorize(type, :bold)}: #{count} docs"
end
print_message(stats.join(', ') + '.')
end
|
.elasticsearch_close(event) ⇒ Object
34
35
36
37
38
|
# File 'lib/esse/cli/event_listener.rb', line 34
def elasticsearch_close(event)
print_message '[%<runtime>s] Index %<name>s successfuly closed',
name: colorize(event[:request][:index], :bold),
runtime: formatted_runtime(event[:runtime])
end
|
.elasticsearch_create_index(event) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/esse/cli/event_listener.rb', line 19
def elasticsearch_create_index(event)
print_message '[%<runtime>s] Index %<name>s successfuly created',
name: colorize(event[:request][:index], :bold),
runtime: formatted_runtime(event[:runtime])
if (aliases = event.to_h.dig(:request, :body, :aliases)).is_a?(Hash)
print_message ' --> Aliases: %<aliases>s', aliases: aliases.keys.join(', ')
end
end
|
.elasticsearch_delete_index(event) ⇒ Object
28
29
30
31
32
|
# File 'lib/esse/cli/event_listener.rb', line 28
def elasticsearch_delete_index(event)
print_message '[%<runtime>s] Index %<name>s successfuly deleted',
name: colorize(event[:request][:index], :bold),
runtime: formatted_runtime(event[:runtime])
end
|
.elasticsearch_open(event) ⇒ Object
40
41
42
43
44
|
# File 'lib/esse/cli/event_listener.rb', line 40
def elasticsearch_open(event)
print_message '[%<runtime>s] Index %<name>s successfuly opened',
name: colorize(event[:request][:index], :bold),
runtime: formatted_runtime(event[:runtime])
end
|
.elasticsearch_reindex(event) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/esse/cli/event_listener.rb', line 99
def elasticsearch_reindex(event)
print_message '[%<runtime>s] Reindex from %<from>s to %<to>s successfuly completed',
from: colorize(event[:request].dig(:body, :source, :index), :bold),
to: colorize(event[:request].dig(:body, :dest, :index), :bold),
runtime: formatted_runtime(event[:runtime])
end
|
.elasticsearch_update_aliases(event) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/esse/cli/event_listener.rb', line 65
def elasticsearch_update_aliases(event)
actions = event[:request].dig(:body, :actions) || []
removed = actions.select { |a| a.key?(:remove) }
added = actions.select { |a| a.key?(:add) }
print_message '[%<runtime>s] Successfuly updated aliases:',
runtime: formatted_runtime(event[:runtime])
removed.each do |action|
print_message '%<padding>s-> Index %<name>s removed from alias %<alias>s',
name: colorize(action[:remove][:index], :bold),
alias: colorize(action[:remove][:alias], :bold),
padding: runtime_padding(event[:runtime])
end
added.each do |action|
print_message '%<padding>s-> Index %<name>s added to alias %<alias>s',
name: colorize(action[:add][:index], :bold),
alias: colorize(action[:add][:alias], :bold),
padding: runtime_padding(event[:runtime])
end
end
|
.elasticsearch_update_mapping(event) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/esse/cli/event_listener.rb', line 46
def elasticsearch_update_mapping(event)
if event[:request][:type]
print_message '[%<runtime>s] Index %<name>s mapping for type %<type>s successfuly updated',
name: colorize(event[:request][:index], :bold),
type: event[:request][:type],
runtime: formatted_runtime(event[:runtime])
else
print_message '[%<runtime>s] Index %<name>s successfuly updated mapping',
name: colorize(event[:request][:index], :bold),
runtime: formatted_runtime(event[:runtime])
end
end
|
.elasticsearch_update_settings(event) ⇒ Object
59
60
61
62
63
|
# File 'lib/esse/cli/event_listener.rb', line 59
def elasticsearch_update_settings(event)
print_message '[%<runtime>s] Index %<name>s successfuly updated settings',
name: colorize(event[:request][:index], :bold),
runtime: formatted_runtime(event[:runtime])
end
|