Reviewed-by: Ren Wen 15991987063@163.com
On Mon, Nov 09, 2020 at 03:07:23PM +0800, Cao Xueliang wrote:
According to scheduler.cr API to refactor sched class.
Extract close_job function from sched.cr to close_job.cr
Signed-off-by: Cao Xueliang caoxl78320@163.com
src/lib/sched.cr | 28 +--------------------------- src/scheduler/close_job.cr | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 src/scheduler/close_job.cr
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index 3709cb1..6aba6cd 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -15,6 +15,7 @@ require "../scheduler/elasticsearch_client"
require "../scheduler/find_job_boot" require "../scheduler/find_next_job_boot" +require "../scheduler/close_job"
class Sched property es @@ -404,33 +405,6 @@ class Sched @redis.hash_set("sched/tbox2ssh_port", testbox, ssh_port) end
- def delete_access_key_file(job : Job)
- File.delete(job.access_key_file) if File.exists?(job.access_key_file)
- end
- def close_job(job_id : String)
- job = @redis.get_job(job_id)
- delete_access_key_file(job) if job
- response = @es.set_job_content(job)
- if response["_id"] == nil
# es update fail, raise exception
raise "es set job content fail!"
- end
- response = @task_queue.hand_over_task(
"sched/#{job.queue}", "extract_stats", job_id
- )
- if response[0] != 201
raise "#{response}"
- end
- @redis.remove_finished_job(job_id)
- return %({"job_id": "#{job_id}", "job_state": "complete"})
- end
- private def query_consumable_keys(shortest_queue_name) keys = [] of String search = "sched/" + shortest_queue_name + "*"
diff --git a/src/scheduler/close_job.cr b/src/scheduler/close_job.cr new file mode 100644 index 0000000..d071d69 --- /dev/null +++ b/src/scheduler/close_job.cr @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+class Sched
- def close_job(job_id : String)
- job = @redis.get_job(job_id)
- delete_access_key_file(job) if job
- response = @es.set_job_content(job)
- if response["_id"] == nil
# es update fail, raise exception
raise "es set job content fail!"
- end
- response = @task_queue.hand_over_task(
"sched/#{job.queue}", "extract_stats", job_id
- )
- if response[0] != 201
raise "#{response}"
- end
- @redis.remove_finished_job(job_id)
- return %({"job_id": "#{job_id}", "job_state": "complete"})
- end
- def delete_access_key_file(job : Job)
- File.delete(job.access_key_file) if File.exists?(job.access_key_file)
- end
+end
2.23.0