From 61a42e63b420f24d147e0165e5a258ff8f369cf3 Mon Sep 17 00:00:00 2001 From: annelin Date: Sat, 4 May 2019 05:40:02 +0300 Subject: [PATCH] Release 0.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [UPD] Now gracefully closes all Telegram and XMPP connections when SIGINT received. I do not fucking know how to deal with memory leaks in Ruby. I tried literally everything. Unloading TD class, forcing garbage collection, et cetera — nothing helps, it just runs a gig in two days. So, now we have to kill -INT our transport every... six hours, for example, and monitor/reconnect (for example with systemd). Fuck ruby & tdlib. Hate. --- inc/xmppcomponent.rb | 12 ++++++++++++ zhabogram.rb | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/inc/xmppcomponent.rb b/inc/xmppcomponent.rb index 4a03156..a5cb6bd 100644 --- a/inc/xmppcomponent.rb +++ b/inc/xmppcomponent.rb @@ -75,6 +75,11 @@ class XMPPComponent @@transport.send(p) end Thread.stop() + rescue Interrupt + @logger.error 'Interrupted!' + @@transport.on_exception do |exception,| end + self.disconnect() + return -11 rescue Exception => e @logger.error 'Connection failed: %s' % e @db.close @@ -82,6 +87,13 @@ class XMPPComponent end end + # transport shutdown # + def disconnect() + @logger.info "Closing all connections..." + @sessions.each do |jid, session| @sessions[jid].disconnect() end + @@transport.close() + end + def survive(exception, stream, state) @logger.error "Stream error on :%s (%s)" % [state.to_s, exception.to_s] @logger.info "Trying to revive session..." diff --git a/zhabogram.rb b/zhabogram.rb index 40bd40f..d670b4e 100644 --- a/zhabogram.rb +++ b/zhabogram.rb @@ -9,9 +9,10 @@ require 'tdlib-ruby' require_relative 'inc/telegramclient' require_relative 'inc/xmppcomponent' -# Configuration file # +# configuration Config = YAML.load_file(File.dirname(__FILE__) + '/config.yml') +TelegramClient.configure(Config['telegram']) # configure tdlib -# Configure Telegram Client # -TelegramClient.configure(Config['telegram']) -XMPPComponent.new(Config['xmpp']).connect() +# run +Zhabogram = XMPPComponent.new(Config['xmpp']) +Zhabogram.connect()