[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 | 33 ++++++++++++++++++++++++++++++- src/lib/web_backend.rb | 13 ++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/container/web-backend/web-backend b/container/web-backend/web-backend index fcc765f..96c2347 100755 --- a/container/web-backend/web-backend +++ b/container/web-backend/web-backend @@ -31,8 +31,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..25b99ea 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -260,6 +260,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 +283,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