Change summary
sgx_endstream.rb | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
Detailed changes
@@ -79,12 +79,34 @@ setup(
async: true
)
+@connected = false
+@shutdown_requested = false
+
when_ready do
+ @connected = true
log.info "Ready"
REDIS = EM::Hiredis.connect
REGISTRATION_REPO = RegistrationRepo.new(redis: REDIS)
end
+disconnected do
+ next if @shutdown_requested
+
+ if @connected
+ log.fatal(
+ "XMPP connection lost",
+ server: "#{CONFIG[:server][:host]}:#{CONFIG[:server][:port]}",
+ component: CONFIG[:component][:jid]
+ )
+ else
+ log.fatal(
+ "Failed to establish XMPP connection",
+ server: "#{CONFIG[:server][:host]}:#{CONFIG[:server][:port]}",
+ component: CONFIG[:component][:jid]
+ )
+ end
+end
+
disco_info to: Blather::JID.new(CONFIG[:component][:jid]) do |iq|
reply = iq.reply
reply.identities = [{
@@ -238,6 +260,6 @@ iq type: [:get, :set] do |iq|
self << iq.as_error("service-unavailable", :cancel)
end
-trap(:INT) { EM.stop }
-trap(:TERM) { EM.stop }
+trap(:INT) { @shutdown_requested = true; EM.stop }
+trap(:TERM) { @shutdown_requested = true; EM.stop }
EM.run { client.run }