Release 0.9
[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.
This commit is contained in:
parent
54860e027a
commit
61a42e63b4
|
@ -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..."
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in a new issue