[Why]
es-jobs's result may need use in other programs.
But it's hard to get it right now.
[How]
use: es_jobs.generate_result can get the hash result
Signed-off-by: Wu Zhende <wuzhende666(a)163.com>
---
lib/es_jobs.rb | 6 +++++-
sbin/es-jobs | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib/es_jobs.rb b/lib/es_jobs.rb
index b0d0fb2..25e54b4 100644
--- a/lib/es_jobs.rb
+++ b/lib/es_jobs.rb
@@ -168,6 +168,10 @@ class ESJobs
end
def output
+ output_yaml('', @result)
+ end
+
+ def generate_result
if @jobs.empty?
puts "No query result is found: #{@es_query}"
return
@@ -175,6 +179,6 @@ class ESJobs
@result = query_jobs_state(@jobs)
@result['kvcount'] = @result['kvcount'].sort.to_h
@result['raw.id'] = @result['raw.id'].sort.to_h
- output_yaml('', @result)
+ @result
end
end
diff --git a/sbin/es-jobs b/sbin/es-jobs
index ff0d540..6d17d6b 100755
--- a/sbin/es-jobs
+++ b/sbin/es-jobs
@@ -52,4 +52,5 @@ items = parse_argv
raise 'Please enter a query' if items.empty?
es_jobs = ESJobs.new(items, opt_refine, opt_fields, opt_stats_filter)
+es_jobs.generate_result
es_jobs.output
--
2.23.0