[why] The "start_time" field need limit by date.
example: GET /get_jobs?upstream_repo=a&page_size=12&start_date=2020-11-03&end_date=2020-11-03
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com --- container/web-backend/web-backend | 35 ++++++++++++++++++++++++++++++- src/lib/web_backend.rb | 15 +++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/container/web-backend/web-backend b/container/web-backend/web-backend index fcc765f..fb519de 100755 --- a/container/web-backend/web-backend +++ b/container/web-backend/web-backend @@ -1,4 +1,6 @@ #!/usr/bin/ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
require 'sinatra' @@ -31,8 +33,39 @@ get '/compare' do compare(params) end
-# GET /get_jobs?upstream_repo=AvxToNeon/AvxToNeon&page_size=12&page_num=3 +# GET /get_jobs?upstream_repo=a&page_size=12&start_date=2020-11-03&end_date=2020-11-03 # upstream_repo: +# - regex search +# > optional +# +# os: +# > optional +# +# os_version: +# > optional +# +# os_arch: +# > optional +# +# suite: +# > optional +# +# category: +# > optional +# +# testbox: +# > optional +# +# job_state: +# > optional +# +# id: +# > optional +# +# start_date: +# > optional +# +# end_date: # > optional # # page_size: diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 55c5e4a..b8df6f4 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
require 'json' @@ -260,6 +262,17 @@ def get_jobs_result(result) jobs end
+def get_job_query_range(condition_fields) + range = { start_time: {} } + start_date = condition_fields[:start_date] + end_date = condition_fields[:end_date] + + range[:start_time][:gte] = "#{start_date} 00:00:00" if start_date + range[:start_time][:lte] = "#{end_date} 23:59:59" if end_date + + { range: range } +end + def search_job(condition_fields, page_size, page_num) must = [] FIELDS.each do |field| @@ -272,6 +285,8 @@ def search_job(condition_fields, page_size, page_num) { term: { field => value } } end end + range = get_job_query_range(condition_fields) + must << range if range[:range][:start_time] result, total = es_search(must, page_size, page_num * page_size) return get_jobs_result(result), total end