[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(a)huawei.com>
---
container/web-backend/web-backend | 57 +++++++++++++++++--------------
src/lib/web_backend.rb | 15 ++++++++
2 files changed, 46 insertions(+), 26 deletions(-)
diff --git a/container/web-backend/web-backend b/container/web-backend/web-backend
index fcc765f..7db82ac 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'
@@ -12,56 +14,59 @@ set :show_exceptions, false
set :environment, :production
# GET /compare_candidates
-# return: {"query_conditions": {...}, "dimension": [...]}
+# Response:
+# - {"query_conditions": {...}, "dimension": [...]}
get '/compare_candidates' do
compare_candidates
end
# GET /compare?suite=borrow&dimension=tbox_group
-# query_conditions:
-# > must
+# must:
+# - query_conditions
# - os / os_version / suite / os_arch / tbox_group
-#
-# dimension:
-# > must
+# - dimension
# - os / os_version / os_arch / suite / tbox_group
#
-# return: compare result string / "No Data." / "No Difference."
+# Response:
+# - compare result string / "No Data." / "No Difference."
get '/compare' do
compare(params)
end
-# GET /get_jobs?upstream_repo=AvxToNeon/AvxToNeon&page_size=12&page_num=3
-# upstream_repo:
-# > optional
-#
-# page_size:
-# > optional
+# GET /get_jobs?upstream_repo=a&page_size=12&start_date=2020-11-03&end_date=2020-11-03
+# optional:
+# - upstream_repo
+# - regex search
+# - os
+# - os_version
+# - os_arch
+# - suite
+# - category
+# - testbox
+# - job_state
+# - id
+# - start_date
+# - end_date
+# - page_size
# - default: 20
-#
-# page_num:
-# > optional
+# - page_num
# - default: 1
#
-# return:
+# Response:
# - default: 20 jobs
get '/get_jobs' do
get_jobs(params)
end
# GET /get_repos?git_repo=a&page_size=12&page_num=3
-# git_repo:
-# > optional
-#
-# page_size:
-# > optional
+# optional:
+# - git_repo
+# - page_size
# - default: 20
-#
-# page_num:
-# > optional
+# - page_num
# - default: 1
#
-# return:
+# Response:
# - default: 20 repos
get '/get_repos' do
get_repos(params)
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
--
2.23.0