For API-level errors, use warn.
For service-level errors, use error.
Signed-off-by: Wu Zhende <wuzhende666(a)163.com>
---
src/lib/sched.cr | 14 ++++++++++++++
src/scheduler.cr | 9 ++++++++-
src/scheduler/close_job.cr | 2 ++
src/scheduler/download_file.cr | 2 ++
src/scheduler/find_job_boot.cr | 2 ++
src/scheduler/find_next_job_boot.cr | 2 ++
src/scheduler/request_cluster_state.cr | 2 ++
src/scheduler/update_job_parameter.cr | 2 ++
8 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr
index f7220f9..be8cac5 100644
--- a/src/lib/sched.cr
+++ b/src/lib/sched.cr
@@ -45,6 +45,8 @@ class Sched
def alive(version)
debug_message("Env= {\n#{`export`}}")
"LKP Alive! The time is #{Time.local}, version = #{version}"
+ rescue e
+ @log.warn(e)
end
def normalize_mac(mac : String)
@@ -59,6 +61,8 @@ class Sched
else
"No yet!"
end
+ rescue e
+ @log.warn(e)
end
def del_host_mac
@@ -69,6 +73,8 @@ class Sched
else
"No yet!"
end
+ rescue e
+ @log.warn(e)
end
def set_host2queues
@@ -79,6 +85,8 @@ class Sched
else
"No yet!"
end
+ rescue e
+ @log.warn(e)
end
def del_host2queues
@@ -89,6 +97,8 @@ class Sched
else
"No yet!"
end
+ rescue e
+ @log.warn(e)
end
def update_tbox_wtmp
@@ -118,6 +128,8 @@ class Sched
# json log
hash["testbox"] = testbox
@log.info(hash.to_json)
+ rescue e
+ @log.warn(e)
end
def report_ssh_port
@@ -130,6 +142,8 @@ class Sched
end
@log.info(%({"job_id": "#{job_id}", "state": "set ssh port", "ssh_port": "#{ssh_port}", "tbox_name": "#{testbox}"}))
+ rescue e
+ @log.warn(e)
end
private def query_consumable_keys(shortest_queue_name)
diff --git a/src/scheduler.cr b/src/scheduler.cr
index 41702e7..07b38a3 100644
--- a/src/scheduler.cr
+++ b/src/scheduler.cr
@@ -3,7 +3,14 @@
require "scheduler/scheduler"
require "./scheduler/constants.cr"
+require "./lib/json_logger"
module Scheduler
- Kemal.run(SCHED_PORT)
+ log = JSONLogger.new
+
+ begin
+ Kemal.run(SCHED_PORT)
+ rescue e
+ log.error(e)
+ end
end
diff --git a/src/scheduler/close_job.cr b/src/scheduler/close_job.cr
index d8f80d7..9b4da6a 100644
--- a/src/scheduler/close_job.cr
+++ b/src/scheduler/close_job.cr
@@ -24,5 +24,7 @@ class Sched
@redis.remove_finished_job(job_id)
@log.info(%({"job_id": "#{job_id}", "job_state": "complete"}))
+ rescue e
+ @log.warn(e)
end
end
diff --git a/src/scheduler/download_file.cr b/src/scheduler/download_file.cr
index e1f0c9a..50e27ba 100644
--- a/src/scheduler/download_file.cr
+++ b/src/scheduler/download_file.cr
@@ -10,5 +10,7 @@ class Sched
@log.info(%({"job_id": "#{job_id}", "job_state": "download"}))
send_file @env, file_path
+ rescue e
+ @log.warn(e)
end
end
diff --git a/src/scheduler/find_job_boot.cr b/src/scheduler/find_job_boot.cr
index 9b3db88..5f71b32 100644
--- a/src/scheduler/find_job_boot.cr
+++ b/src/scheduler/find_job_boot.cr
@@ -21,6 +21,8 @@ class Sched
@log.info(%({"job_id": "#{job_id}", "job_state": "boot"})) if job_id
response
+ rescue e
+ @log.warn(e)
end
# auto submit a job to collect the host information
diff --git a/src/scheduler/find_next_job_boot.cr b/src/scheduler/find_next_job_boot.cr
index 0bdfe5b..091c41a 100644
--- a/src/scheduler/find_next_job_boot.cr
+++ b/src/scheduler/find_next_job_boot.cr
@@ -14,5 +14,7 @@ class Sched
@log.info(%({"job_id": "#{job_id}", "job_state": "boot"})) if job_id
response
+ rescue e
+ @log.warn(e)
end
end
diff --git a/src/scheduler/request_cluster_state.cr b/src/scheduler/request_cluster_state.cr
index 1782797..06e3329 100644
--- a/src/scheduler/request_cluster_state.cr
+++ b/src/scheduler/request_cluster_state.cr
@@ -68,6 +68,8 @@ class Sched
# show cluster state
return @redis.hash_get("sched/cluster_state", cluster_id)
+ rescue e
+ @log.warn(e)
end
# node_state: "finish" | "ready"
diff --git a/src/scheduler/update_job_parameter.cr b/src/scheduler/update_job_parameter.cr
index da528c1..744274a 100644
--- a/src/scheduler/update_job_parameter.cr
+++ b/src/scheduler/update_job_parameter.cr
@@ -30,5 +30,7 @@ class Sched
log = job_content.dup
log["job_id"] = log.delete("id").not_nil!
@log.info(log.to_json)
+ rescue e
+ @log.warn(e)
end
end
--
2.23.0