According to scheduler.cr API to refactor sched class.
Extract update_job_parameter function from sched.cr to update_job_parameter.cr
Signed-off-by: Cao Xueliang caoxl78320@163.com --- src/lib/sched.cr | 31 +----------------------- src/scheduler/update_job_parameter.cr | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 src/scheduler/update_job_parameter.cr
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index 1b6eb8a..e966ae2 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -17,6 +17,7 @@ require "../scheduler/find_job_boot" require "../scheduler/find_next_job_boot" require "../scheduler/close_job" require "../scheduler/request_cluster_state" +require "../scheduler/update_job_parameter"
class Sched property es @@ -236,36 +237,6 @@ class Sched extra_job_fields) if Dir.glob(full_path_patterns).size > 0 end
- def update_job_parameter(env : HTTP::Server::Context) - job_id = env.params.query["job_id"]? - if !job_id - return false - end - - # try to get report value and then update it - job_content = {} of String => String - job_content["id"] = job_id - - (%w(start_time end_time loadavg job_state)).each do |parameter| - value = env.params.query[parameter]? - if !value || value == "" - next - end - if parameter == "start_time" || parameter == "end_time" - value = Time.unix(value.to_i).to_local.to_s("%Y-%m-%d %H:%M:%S") - end - - job_content[parameter] = value - end - - @redis.update_job(job_content) - - # json log - log = job_content.dup - log["job_id"] = log.delete("id").not_nil! - return log.to_json - end - def update_tbox_wtmp(env : HTTP::Server::Context) testbox = "" hash = Hash(String, String).new diff --git a/src/scheduler/update_job_parameter.cr b/src/scheduler/update_job_parameter.cr new file mode 100644 index 0000000..0692025 --- /dev/null +++ b/src/scheduler/update_job_parameter.cr @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +class Sched + def update_job_parameter(env : HTTP::Server::Context) + job_id = env.params.query["job_id"]? + if !job_id + return false + end + + # try to get report value and then update it + job_content = {} of String => String + job_content["id"] = job_id + + (%w(start_time end_time loadavg job_state)).each do |parameter| + value = env.params.query[parameter]? + if !value || value == "" + next + end + if parameter == "start_time" || parameter == "end_time" + value = Time.unix(value.to_i).to_local.to_s("%Y-%m-%d %H:%M:%S") + end + + job_content[parameter] = value + end + + @redis.update_job(job_content) + + # json log + log = job_content.dup + log["job_id"] = log.delete("id").not_nil! + return log.to_json + end +end