[Why]
If the connection to the mq service is disconnected,
the interface for sending messages is abnormal,
affecting the main logic.
[How]
Start a thread to send mq messages.
Reconnect and send every 5 seconds, three attempts.
Signed-off-by: Wu Zhende <wuzhende666(a)163.com>
---
src/lib/sched.cr | 10 ++++++++++
src/scheduler/close_job.cr | 2 +-
src/scheduler/find_job_boot.cr | 2 +-
src/scheduler/update_job_parameter.cr | 2 +-
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr
index f5aba03..9528f54 100644
--- a/src/lib/sched.cr
+++ b/src/lib/sched.cr
@@ -218,4 +218,14 @@ class Sched
return nil
end
+
+ def mq_pushlish_confirm(queue, msg)
+ 3.times do
+ @mq.pushlish_confirm(queue, msg)
+ break
+ rescue e
+ res = @mq.reconnect
+ sleep 5
+ end
+ end
end
diff --git a/src/scheduler/close_job.cr b/src/scheduler/close_job.cr
index ea1dbf5..e014361 100644
--- a/src/scheduler/close_job.cr
+++ b/src/scheduler/close_job.cr
@@ -45,7 +45,7 @@ class Sched
"job_state" => "close",
"time" => get_time
}
- @mq.pushlish_confirm(JOB_MQ, mq_msg.to_json)
+ spawn mq_pushlish_confirm(JOB_MQ, mq_msg.to_json)
end
end
end
diff --git a/src/scheduler/find_job_boot.cr b/src/scheduler/find_job_boot.cr
index ce1a2f8..9e83537 100644
--- a/src/scheduler/find_job_boot.cr
+++ b/src/scheduler/find_job_boot.cr
@@ -32,7 +32,7 @@ class Sched
"time" => get_time,
"job_state" => "boot"
}
- @mq.pushlish_confirm(JOB_MQ, mq_msg.to_json)
+ spawn mq_pushlish_confirm(JOB_MQ, mq_msg.to_json)
end
# auto submit a job to collect the host information.
diff --git a/src/scheduler/update_job_parameter.cr b/src/scheduler/update_job_parameter.cr
index b43aa06..d81f28b 100644
--- a/src/scheduler/update_job_parameter.cr
+++ b/src/scheduler/update_job_parameter.cr
@@ -44,6 +44,6 @@ class Sched
"job_state" => (@env.get?("job_state") || "update").to_s,
"time" => @env.get?("time").to_s
}
- @mq.pushlish_confirm(JOB_MQ, mq_msg.to_json)
+ spawn mq_pushlish_confirm(JOB_MQ, mq_msg.to_json)
end
end
--
2.23.0