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)
|
@@transport.send(p)
|
||||||
end
|
end
|
||||||
Thread.stop()
|
Thread.stop()
|
||||||
|
rescue Interrupt
|
||||||
|
@logger.error 'Interrupted!'
|
||||||
|
@@transport.on_exception do |exception,| end
|
||||||
|
self.disconnect()
|
||||||
|
return -11
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@logger.error 'Connection failed: %s' % e
|
@logger.error 'Connection failed: %s' % e
|
||||||
@db.close
|
@db.close
|
||||||
|
@ -82,6 +87,13 @@ class XMPPComponent
|
||||||
end
|
end
|
||||||
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)
|
def survive(exception, stream, state)
|
||||||
@logger.error "Stream error on :%s (%s)" % [state.to_s, exception.to_s]
|
@logger.error "Stream error on :%s (%s)" % [state.to_s, exception.to_s]
|
||||||
@logger.info "Trying to revive session..."
|
@logger.info "Trying to revive session..."
|
||||||
|
|
|
@ -9,9 +9,10 @@ require 'tdlib-ruby'
|
||||||
require_relative 'inc/telegramclient'
|
require_relative 'inc/telegramclient'
|
||||||
require_relative 'inc/xmppcomponent'
|
require_relative 'inc/xmppcomponent'
|
||||||
|
|
||||||
# Configuration file #
|
# configuration
|
||||||
Config = YAML.load_file(File.dirname(__FILE__) + '/config.yml')
|
Config = YAML.load_file(File.dirname(__FILE__) + '/config.yml')
|
||||||
|
TelegramClient.configure(Config['telegram']) # configure tdlib
|
||||||
|
|
||||||
# Configure Telegram Client #
|
# run
|
||||||
TelegramClient.configure(Config['telegram'])
|
Zhabogram = XMPPComponent.new(Config['xmpp'])
|
||||||
XMPPComponent.new(Config['xmpp']).connect()
|
Zhabogram.connect()
|
||||||
|
|
Reference in a new issue