Signed-off-by: Cao Xueliang <caoxl78320(a)163.com>
---
container/assist-result/routes.rb | 6 +++---
.../views/{get_job_stats.rb => get_job_content.rb} | 5 ++---
lib/assist_result_client.rb | 8 ++++++++
src/delimiter/utils.rb | 7 +++++--
4 files changed, 18 insertions(+), 8 deletions(-)
rename container/assist-result/views/{get_job_stats.rb => get_job_content.rb} (67%)
diff --git a/container/assist-result/routes.rb b/container/assist-result/routes.rb
index 02956aa..287db25 100755
--- a/container/assist-result/routes.rb
+++ b/container/assist-result/routes.rb
@@ -7,7 +7,7 @@ require 'json'
require 'sinatra'
require_relative './views/get_job_yaml'
-require_relative './views/get_job_stats'
+require_relative './views/get_job_content'
require_relative './views/check_job_credible'
configure do
@@ -36,9 +36,9 @@ post '/check_job_credible' do
return [200, {'credible' => result}.to_json]
end
-get '/get_job_stats/:job_id' do
+get '/get_job_content/:job_id' do
begin
- result = get_job_stats(params[:job_id])
+ result = get_job_content(params[:job_id])
rescue StandardError => e
return [400, e.backtrace.inspect]
end
diff --git a/container/assist-result/views/get_job_stats.rb b/container/assist-result/views/get_job_content.rb
similarity index 67%
rename from container/assist-result/views/get_job_stats.rb
rename to container/assist-result/views/get_job_content.rb
index d294df3..643beb5 100644
--- a/container/assist-result/views/get_job_stats.rb
+++ b/container/assist-result/views/get_job_content.rb
@@ -4,7 +4,6 @@
require_relative "#{ENV['CCI_SRC']}/lib/es_query"
-def get_job_stats(job_id)
- content = ESQuery.new.query_by_id(job_id)
- return content['stats']
+def get_job_content(job_id)
+ return ESQuery.new.query_by_id(job_id)
end
diff --git a/lib/assist_result_client.rb b/lib/assist_result_client.rb
index fcf5d9d..9c42b97 100644
--- a/lib/assist_result_client.rb
+++ b/lib/assist_result_client.rb
@@ -34,4 +34,12 @@ class AssistResult
return JSON.parse(response.body)
end
+
+ def get_job_content(job_id)
+ resource = RestClient::Resource.new("http://#{@host}:#{@port}/get_job_content/#{job_id}")
+ response = resource.get()
+ return nil unless response.code == 200
+
+ return response.body
+ end
end
diff --git a/src/delimiter/utils.rb b/src/delimiter/utils.rb
index dbc42ef..a39d9de 100644
--- a/src/delimiter/utils.rb
+++ b/src/delimiter/utils.rb
@@ -108,9 +108,12 @@ module Utils
# this is a temporary solution, the extract container will be improved in future.
def query_stats(job_id, times)
(1..times).each do |i|
- new_job = ESQuery.new.query_by_id(job_id)
+ job_content = AssistResult.new.get_job_content(job_id)
puts "query stats times: #{i}"
- return new_job['stats'] if new_job['stats']
+ if job_content
+ job_content = JSON.parse(job_content)
+ return job_content['stats'] if job_content.key?('stats')
+ end
sleep 60
end
--
2.23.0